Unregistered
$session_key="id";
$session_value = "data";
$session_time = "expire";
$db = "";
$expire = 300;
function sess_open($save_path, $session_name){
global $dbhost, $dbuser, $dbpasswd, $db;
if (! $db = mysql_pconnect($dbhost, $dbuser, $dbpasswd)){
echo mysql_error();
exit;
}
return true;
}
function sess_close(){
return true;
}
function sess_read($key){
global $db, $dbname, $t_sessions, $session_key, $session_value, $session_time;
$query = "select $session_value from $t_sessions where $session_key = \'$key\' and $session_time > UNIX_TIMESTAMP()";
$result = mysql_db_query($dbname, $query, $db);
if($record = mysql_fetch_row($result)){
return $record[0];
} else {
return false;
}
}
function sess_write($key, $val){
global $db, $dbname, $t_sessions, $expire;
$value = addslashes($val);
$query = "replace into $t_sessions values (\'$key\', \'$value\', UNIX_TIMESTAMP() + $expire)";
$result = mysql_db_query($dbname, $query, $db);
echo mysql_error();
return $result;
}
function sess_destroy($key){
global $db, $dbname, $t_sessions, $session_key;
$query = "delete from $t_sessions where session_key = \'$key\'";
$result = mysql_db_query($dbname, $query, $db);
return $result;
}
function sess_gc($maxlifetime){
global $db, $dbname, $t_sessions, $session_time;
$query = "delete from $t_sessions where session_time < UNIX_TIMESTAMP()";
$result = mysql_db_query($dbname, $query, $db);
return mysql_affected_rows($db);
}
session_set_save_handler("sess_open","sess_close","sess_read","sess_write","sess_destroy","sess_gc");