Solved

get all info about a session

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now