Solved

get all info about a session

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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