Dear bradgrafelman,
i think i'm heading towards the wrong direction in the first place.
i discovered when i first load the page, there was no session created!
Then when i refresh the page, a session was created.
Q1) Is there something wrong with my code below that it does not create a session in the first loading.
Q2) this function session_destroyer(session_id()); is not working for me.
Q3) when will this function session_clean() executed automatically?
comfunction.php
function session_open() { return true; }
function session_close() { return true; }
function session_read($id)
{
$sql = "SELECT session_data FROM " . TBL_ERROR . " WHERE session_id = '$id'";
if ($result = mysql_query($sql))
{
if (mysql_num_rows($result))
{
$record = mysql_fetch_assoc($result);
return $record['session_data'];
}
}
return '';
}
function session_write($id, $data)
{
$date = time();
mysql_query("REPLACE INTO " . TBL_ERROR . " VALUES ('$id', '$date', '$data')");
}
function session_destroyer($id)
{
mysql_query( "DELETE FROM " . TBL_ERROR . " WHERE session_id = '$id'" );
}
function session_clean()
{
$expireTime = time() - SESSION_TIME_LIMIT;
mysql_query("DELETE FROM " . TBL_ERROR . " WHERE session_date < $expireTime");
}
session_set_save_handler('session_open','session_close','session_read','session_write','session_destroyer','session_clean');
main.php
include('comfunction.php');
session_start();
$_SESSION.....
......