?
Solved

get all info about a session

Posted on 2008-10-10
2
Medium Priority
?
234 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
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
yessirnosir earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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