Page 1 of 1

Listing Every Session Variable

Posted: Wed Jul 12, 2006 1:58 pm
by tecktalkcm0391
Is there a way to make PHP print:

$_SESSION['name'] = hi
$_SESSION['name2'] = asdf
$_SESSION['name3'] = hh

which is pretty much just it finding all of the sessions variables and then printing it. What I just want is a list of all of the variables on the page, so that I can be lazy an not have to find them all

Posted: Wed Jul 12, 2006 2:16 pm
by Oren

Code: Select all

<?php

	print_r($_SESSION);

?>

Posted: Wed Jul 12, 2006 2:16 pm
by Benjamin

Code: Select all

print_r($_SESSION);

// or if your REALLY  lazy..
print_r($GLOBALS);

Posted: Wed Jul 12, 2006 2:22 pm
by Christopher
A number of programmers keep something like this around. I stick it in config.php and comment out the echo in production code to minimize stray print statements.

Code: Select all

function dump($var) {
     echo '<pre>' . print_r($var, 1) . '</pre>';
}

Posted: Wed Jul 12, 2006 2:26 pm
by Ollie Saunders
arborint wrote:A number of programmers keep something like this around. I stick it in config.php and comment out the echo in production code to minimize stray print statements.

Code: Select all

function dump($var) {
     echo '<pre>' . print_r($var, 1) . '</pre>';
}
Yeah i do that.

Posted: Wed Jul 12, 2006 2:26 pm
by Oren
arborint wrote:A number of programmers keep something like this around. I stick it in config.php and comment out the echo in production code to minimize stray print statements.

Code: Select all

function dump($var) {
     echo '<pre>' . print_r($var, 1) . '</pre>';
}
What's wrong with:

Code: Select all

<?php

        print_r($_SESSION);

?>
Except to the presentation?

Posted: Wed Jul 12, 2006 2:32 pm
by R4000
I prefer to use var_dump() myself...
It gives you alot more detailed info than print_r().

But thats just me :)
(i deal with alot of binary reverse engineering in PHP :P so i need to know true string lengths ect.)

Posted: Wed Jul 12, 2006 2:36 pm
by Oren
R4000 wrote:I prefer to use var_dump() myself...
It gives you alot more detailed info than print_r().

But thats just me :)
(i deal with alot of binary reverse engineering in PHP :P so i need to know true string lengths ect.)
This really depends on your needs... For me, most of the time the extra data from var_dump() is useless and confusing - Not because I don't understand it :P , but because this is an extra text to read even though I don't need this information (in most cases).