Without having to call each session variable by name, is there a way to display the content of all the session variables currently set?
Use this: echo '<pre>'; var_dump($_SESSION); echo '</pre>'; Or you can use print_r if you don't care about types.
If you want to print the full array, as a string, try print_r($array); .
php session_start(); echo "<h3> PHP List All Session Variables</h3>"; foreach ($_SESSION as $key=>$val) echo $key." ".
You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable.
echo '<pre>'; var_dump($_SESSION); echo '</pre>';
Or you can use print_r
if you don't care about types. If you use print_r
, you can make the second argument TRUE
so it will return instead of echo, useful for...
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With