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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.