Solved

get all info about a session

Posted on 2008-10-10
2
219 Views
Last Modified: 2012-05-05
hi expert,

I am trying to get the following formation of a session ( using php)

1- the date first created
2- the date last updated
and every other information I can get...


thx
0
Comment
Question by:uk1900
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
yessirnosir earned 500 total points
ID: 22687220
Here's a little script that gets the session ID and the creation and modified timestamps, plus prints out the contents of the session array.
It relies on knowing the path to the temporary folder that contains the session file (variable $sessfile).  On my server, the path shown works, but you may have to modify.

One significant issue:  when I run this on my local Windows XAMPP setup it gets different timestamps for creation and modified, but on my live server running Linux/Apache, I get the same time stamp for created and modified.  Did some googling and it appears this is just the way Linux file system works -- creation time is the time the file was last changed.  So I'm stumped about how to get the true session creation time in a Linux environment.
<?php  session_start();
$_SESSION['testvalue']="test string 1";
$_SESSION['testvalue2']="test string 2";
?>
<html>
<head>
<title>Checking PHP session info</title>
</head>
<body>
<?php  
$sid=session_id();
$sessfile="/tmp/sess_".$sid;
echo $msg. "<BR>"; 
echo "Session ID is: ". $sid. "<BR>"; 
echo "Session was created at: ".date("m/d/y H:i:s T", filectime($sessfile)). "<BR>";
echo "Session was modified at: ".date("m/d/y H:i:s T", filemtime($sessfile)). "<BR>";
foreach ($_SESSION as $i => $value) {
echo "Value: $i : $value <br />";}
?>
</body>
</html>

Open in new window

0
 
LVL 14

Expert Comment

by:yessirnosir
ID: 22687367
a slight mod to above; following two lines should pull the session path from the environment so you don't have to know what the path is.  They would replace line 12 above:
$sessionpath = session_save_path();
$sessfile=$sessionpath."/sess_".$sid;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question