PHP如何将Session存储在数据库中(5)
最后,destroy函数删除具有给定会话ID的所有记录,gc函数删除过期的会话数据,也就是比当前时间减去传递的maxLifeTime参数(秒数)要陈旧的会话数据。
public static function destroy( $id )
{
$id=self::$s_conn->real_escape_string($id);
$query=”DELETE FROM SessionData WHERE session_id=’$id’”;
$result=@self::$s_conn->query($query);
if(self::$s_conn->errno!=0)
return false;
else
return true;
}
public static function gc( $maxLifeTime )
{
$maxDate = date (’Y-m-d H:m:s’, time()-$maxLifeTime);
$query=<<<EOQUERY
DELETE FROM SessionData where last_update<’$maxDate’
EOQUERY;
$result=@self::$s_conn->query($query);
if(self::$s_conn->errno !=0)
return FALSE;
return TRUE;
}
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
还没有评论。
发表评论