if ($rs = self::$_db->query('SELECT SQL_NO_CACHE data FROM sessions WHERE id = 0x' . $id . ' LIMIT 1'))
{
$row = $rs->fetch_row();
$rs->free_result();
return (string) $row[0];
}
}
return '';
}
static function write($id, $data)
{
if (isset($_COOKIE[session_name()])) // WARNING: This will NOT write the session on the first page view! The cookie MUST be created/set first, which requires another page view before it works! This prevents bots from creating sessions! But during testing a new session_id() or browser, it can be confusing because you won't see a new session until your second page view!
// Taken from: http://www.php.net/manual/en/function.session-destroy.php
// `session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.`
static function destroy($id)
{
self::$_db->real_query('DELETE FROM sessions WHERE id = 0x' . $id);
return true;
}
static function gc($ttl)
{
self::$_db->real_query('DELETE FROM sessions WHERE timestamp <UNIX_TIMESTAMP()-'.$ttl.'ANDpersistent =0');//$ttl =1440(default)=24minutes