Solved

get all info about a session

Posted on 2008-10-10
2
217 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to count occurrences of each item in an array.

789 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