Start a PHP Session
A session is started with the session_start() function.
Session variables are set with the PHP global variable: $_SESSION.
Create a new page called "test_session1.php". In this page, we start a new PHP session and set some session variables:create a page called "test_session.php". From this page, you will access the session information we set on the first page ("test_session1.php").
the session variables are not passed individually to each new page, instead, they are retrieved from the session we open at the beginning of each page (session_start()).
All session variable values are stored in the global $_SESSION variable:
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "pink";
$_SESSION["favanimal"] = "goat";
echo "Session variables are set.";
?>
Get PHP Session Variable Values
Create another page called "test_session2.php". From this page, we will access the session information we set on the first page ("test_session1.php").
Session variables are not passed individually to each new page, instead, they are retrieved from the session we open at the beginning of each page (session_start()).
All session variable values are stored in the global $_SESSION variable:
Another way is to print session variables
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
print_r($_SESSION);
?>
</body>
</html>