If you have already register Login here.
PHP session is used to store and pass information from one page to another temporarily (until the user closes the website).
PHP session technique is widely used in shopping websites where we need to store and pass cart information e.g. username, product code, product name, product price, etc from one page to another.
PHP session creates a unique user id for each browser to recognize the user and avoid conflict between multiple browsers.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser.
So; Session variables hold information about one single user, and are available to all pages in one application.
Tip: If you need permanent storage, you may want to store the data in a database.
PHP session_start() function is used to start the session. It starts a new or resumes existing session. It returns the existing session if the session is created already. If the session is not available, it creates and returns a new session.
bool session_start ( void )
session_start();
PHP $_SESSION is an associative array that contains all session variables. It is used to set and get session variable values.
$_SESSION["user"] = "Karan";
echo $_SESSION["user"];
File Name: session_file.php
<?php
session_start();
?>
<html>
<body>
<?php
$_SESSION["user"] = "Karan";
echo "Session information are set successfully.<br/>";
?>
<a href="session_file2.php">Visit next page</a>
</body>
</html>
© 2025 Easy To Learning. All Rights Reserved | Design by Easy To Learning