[PHP] Zhang Session Expiration

2002-01-07 Thread phantom

Hey all,

I am using the Zhang session method from
http://www.phpbuilder.com/columns/ying2602.php3  and it works great
with a mysql database.

Does anyone out there know how to tell if a session is expired using
this method?  The Read Session function is:
\\---;
function sess_read($key) {
 global $SESS_DBH, $SESS_LIFE;

 $qry = SELECT value FROM Sessions WHERE sesskey = '$key' AND expiry 
 . time();
 $qid = mysql_query($qry, $SESS_DBH);

 if (list($value) = mysql_fetch_row($qid)) {
  return $value;
 }

 return false;
}
\\---;

So if session is expired, this script will return nothing (per the
expiry WHERE clause).

Say I had placed a variable called $NameOfUser in the session data using
session_register($NameOfUser), if the session is expired, would I be
able to know that it was expired by using isset($NameOfUser) after
running the session_register($NameOfUser) in the script??

Thanks.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Zhang Session Expiration

2002-01-07 Thread Michael Sims

At 07:20 AM 1/7/2002 -0600, phantom wrote:
Hey all,

I am using the Zhang session method from
http://www.phpbuilder.com/columns/ying2602.php3  and it works great
with a mysql database.

Does anyone out there know how to tell if a session is expired using
this method?

Yep.  The expiry field is equal to the UNIX timestamp at which the 
session will expire.  To get a list of sessions that have already expired, 
you can use this:

$query = SELECT * FROM sessions WHERE expiry   . time();

Say I had placed a variable called $NameOfUser in the session data using
session_register($NameOfUser), if the session is expired, would I be
able to know that it was expired by using isset($NameOfUser) after
running the session_register($NameOfUser) in the script??

That sounds about right.  You might want to try:

if (!session_is_registered(NameOfUser)) {
 //restart session
}

Although I don't know if that function is reliable with the custom session 
handler...I think it should be though.

I've been using that exact same session handler for several weeks in one of 
my scripts and it works great


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]