Jump to content

output session variables


haku

Recommended Posts

Actually what you're really after is the

<?php
$keys = array_keys($_SESSION);
foreach($keys as $k){
echo $k;
}
?>

 

The above will fetch all the key names of your associative array (which is what the session is essentially). print_r has it's uses (for debugging) but you can't use the key names with it ;)

Thank you aschk, that helped a lot. print_r unfortunately didn't work the way I wanted.

 

For anyone who may see this thread in the future, I ended up using this code (a slight variation on aschk's):

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                              "XHTML1-s.dtd" >
<html>
<head>
	<title>Session Variable List</title>
	<style type="text/css">
		table
		{
			border: 3px solid #000000;
			border-collapse: collapse;
		}
		td
		{
			border: 1px solid #000000;
		}
	</style>
</head>
<body>
	<table>
		<thead>
			<tr>
				<td>Variable Name</td>
				<td>Value</td>
			</tr>
		</thead>
		<tbody>

<?php
session_start();
$keys = array_keys($_SESSION);

foreach($keys as $k)
{
 	echo "<tr><td>" . $k . "</td><td> " . $_SESSION[$k] . "</td></tr>";
}
?>
		</tbody>
	</table>
</body>
</html>

 

This outputs all the session variables names and their values in a nice little easy to read table.

I have my own mini library of scripts like that. I use them for testing purposes - I drop them onto my server and delete them after use. I like to make them valid just cause Im an@l that way. The core of what I was doing was what Thorpe showed, but I prefer the full deal for myself.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.