PHP Knowledge Base
List All Session Variables
Example 1
Code:
echo '<pre>'; var_dump($_SESSION); echo '</pre>';
Result:
array(8) { ["msg"]=> string(21) "You must log in first" ["session__gym_table"]=> string(20) "gym__2017__curr__ssm" ["session__year"]=> string(4) "2018" ["session__month"]=> string(1) "7" ["username"]=> string(6) "FAKENAME" ["success"]=> string(21) "You are now logged in" ["session__workout__day"]=> string(2) "22" ["session__body_part"]=> string(15) "body_part__back" }
Example 2
Code:
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
Result:
Array ( [msg] => You must log in first [session__gym_table] => gym__2017__curr__ssm [session__year] => 2018 [session__month] => 7 [username] => FAKENAME [success] => You are now logged in [session__workout__day] => 22 [session__body_part] => body_part__back )
Example 3
Code:
session_start(); foreach ($_SESSION as $name => $value) { echo $name."=".$value."<br>"; }
Result:
msg=You must log in first username=craigd success=You are now logged in session__gym_table=gym__2017__curr__ssm session__year=2018 session__month=7