Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print all session variables currently set?

Tags:

php

session

Without having to call each session variable by name, is there a way to display the content of all the session variables currently set?

like image 717
Georgy Avatar asked Jul 26 '10 00:07

Georgy


People also ask

How would you print all of the variables being used in the session?

Use this: echo '<pre>'; var_dump($_SESSION); echo '</pre>'; Or you can use print_r if you don't care about types.

How do I print a session array?

If you want to print the full array, as a string, try print_r($array); .

How can I see all sessions in PHP?

php session_start(); echo "<h3> PHP List All Session Variables</h3>"; foreach ($_SESSION as $key=>$val) echo $key." ".

How do you check session variable is set or not?

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.


1 Answers

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>'; 
like image 102
alex Avatar answered Oct 04 '22 04:10

alex