note 34394 added to function.session-set-save-handler
| From: | rafael dot tz at uol dot com dot br | Date: | Fri, 25 Jul 2003 16:38:47 +0000 |
| Subject: | note 34394 added to function.session-set-save-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52650@lists.php.net to get a copy of this message | ||
Hi people! I was wondering about a MySQL Sessions control... Here is some of my work, a little mod
on some cods that I've found this far:
if(!mysql_table_exists("sessions",$DB))
{
$query = 'CREATE TABLE sessions
(
SessionID char(255) not null,
LastUpdated datetime not null,
DataValue text,
PRIMARY KEY ( SessionID ),
INDEX ( LastUpdated )
)';
mysql_query($query);
}
function sessao_open($aSavaPath, $aSessionName)
{
global $aTime;
sessao_gc( $aTime );
return True;
}
function sessao_close()
{
return True;
}
function sessao_read( $aKey )
{
$query = "SELECT DataValue FROM sessions WHERE SessionID='$aKey'";
$busca = mysql_query($query);
if(mysql_num_rows($busca) == 1)
{
$r = mysql_fetch_array($busca);
return $r['DataValue'];
} ELSE {
$query = "INSERT INTO sessions (SessionID, LastUpdated, DataValue)
VALUES ('$aKey', NOW(), '')";
mysql_query($query);
return "";
}
}
function sessao_write( $aKey, $aVal )
{
$aVal = addslashes( $aVal );
$query = "UPDATE sessions SET DataValue = '$aVal', LastUpdated = NOW() WHERE
SessionID = '$aKey'";
mysql_query($query);
return True;
}
function sessao_destroy( $aKey )
{
$query = "DELETE FROM sessions WHERE SessionID = '$aKey'";
mysql_query($query);
return True;
}
function sessao_gc( $aMaxLifeTime )
{
$query = "DELETE FROM sessions WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(LastUpdated)
> $aMaxLifeTime";
mysql_query($query);
return True;
}
session_set_save_handler("sessao_open", "sessao_close", "sessao_read",
"sessao_write", "sessao_destroy", "sessao_gc");
----
Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34394
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34394&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34394&report=yes