Re: check if user session exists
| From: | Rob Adams | Date: | Mon, 09 Feb 2004 23:18:34 +0000 |
| Subject: | Re: check if user session exists | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177239@lists.php.net to get a copy of this message | ||
"Christian Calloway" <callowaylc@yahoo.com> wrote in message
news:20040209202744.44416.qmail@pb1.pair.com...
> Yeah thats pretty much what I have concluded. I was absolutely sure there
> would be a way to check if a session was still active, but I guess not
:-(.
> Thanks though
It depends on your definition of 'active.' If you wanted to see if the
specific session you are looking at has been used in the past half hour,
that is possible. Following is a script I've used to help debug sessions
sometimes. While it's not what you're asking for, it may help you figure
out how to do it. It may need tweaking to run on your server.
<? // sessioninfo.php
$path = ini_get('session.save_path');
if (isset($_GET['empty']))
{
if (isset($_COOKIE['PHPSESSID']))
setcookie('PHPSESSID', '');
header('Location: sessioninfo.php');
}
if (count($_GET) == 0)
{
echo "<br>Path: $path<br>";
$dir = dir($path);
while ($file = $dir->read())
{
$file_arr[$file]['time'] = filectime($path . '/' . $file);
$file_arr[$file]['size'] = filesize($path . '/' . $file);
}
$dir->close();
asort($file_arr);
echo '<table
border=1><tr><th>Time</th><th>Size</th><th>SessionID</th></tr>';
foreach($file_arr as $fname => $data)
{
if ($fname == '.' || $fname == '..')
continue;
$ftime = date('Y-m-d G:i', $data['time']);
$sessid = substr($fname, 5);
echo
"<tr><td>$ftime</td><td>{$data['size']}</td><td><a
href=\"?sessionid=$sessid\">$fname</a></td></tr>";
}
echo '</table>';
} else if (isset($_GET['sessionid'])) {
setcookie('PHPSESSID', $_GET['sessionid']);
header('Location: sessioninfo.php?show=true');
exit();
} else {
session_start();
echo '<pre>';
print_r($_SESSION);
print_r($_GET);
echo '</pre>';
}
?>
>
> Christian
>
> "Larry Brown" <larry.brown@dimensionnetworks.com> wrote in message
>
> news:CBECIONKKLMDDCIKHALJCEEIKDAA.larry.brown@dimensionnetworks.com...
> > I don't know of a function, but you could possibly read the directory
> where
> > the SID files are stored. I use sessions a lot; however, I've not tried
> to
> > accomplish this. I don't know if by default you can read the SID
> directory
> > from a script or if this is blocked for security reasons or not. If
not,
> > you could read the directory, match the SIDs from your list and go from
> > there. There is no way of knowing if the person is still actively using
> the
> > SID this way though.
> >
> > Larry.
> >
> > -----Original Message-----
> > From: Christian Calloway [mailto:callowaylc@yahoo.com]
> > Sent: Monday, February 09, 2004 9:28 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] check if user session exists
> >
> >
> > Given a set of session id's, is it possible to query whether a given
> session
> > exists. I am not talking about the current user session, instead I am
> > referring to any and all possible user sessions currently in play. For
> > example:
> >
> > if (session_exists($sessionId)) doSomething();
> >
> > I've been looking very hard for this one and haven't found an answer at
> all.
> > Any ideas?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php