0

Hi everyone,

I strongly believe that this topic will not just help me but everyone else using php.

My question is how to manually change the settings where in the storage of the sessions is set to the database tables that we will create in the phpmyadmin (mysql)?

I have checked,

session_set_save_handler() 

but still cannot figure out how to make it work.. any help would be very much
appreciated.

If anybody knows a layman - tutorial for this that would also be great.

TIA

Edited by happygeek: fixed formatting

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by d3rck
0

Ok, so I found a script to play around with..

I still can't make it work.

Anyone has any ideas?

function open()
{
global $_sess_db;
if ($_sess_db = mysql_connect("$dbserver", "$dbusername", "$dbpassword")) 
{
return mysql_select_db(mysql_select_db("mydatabase"));
}
return FALSE;
}

function close()
{
global $_sess_db;
return mysql_close($_sess_db);
}

function read($sessionid)
{
global $_sess_db;
$sessionid = mysql_real_escape_string($sessionid);
$sql = "SELECT data FROM session WHERE sessionid = '$sessionid'";
if ($result = mysql_query($sql, $_sess_db)) 
{
if (mysql_num_rows($result)) 
{
$record = mysql_fetch_assoc($result);
return $record['data'];
}
}
return '';
}

function write($sessionid, $data)
{
global $_sess_db;
$access = date('Y-m-d H:i:s'); // REPLACED WITH DATETIME
$sessionid = mysql_real_escape_string($sessionid);
$access = mysql_real_escape_string($access);
$data = mysql_real_escape_string($data);
$sql = "REPLACE INTO session VALUES ('$sessionid', '$access', '$data')";
return mysql_query($sql, $_sess_db);
}

function destroy($sessionid)
{
global $_sess_db;
$sessionid = mysql_real_escape_string($sessionid);
$sql = "DELETE FROM session WHERE sessionid = '$sessionid'";
return mysql_query($sql, $_sess_db);
}

function clean($max)
{
global $_sess_db;
$old = time() - $max;
$old = mysql_real_escape_string($old);
$sql = "DELETE FROM session WHERE access < '$old'";
return mysql_query($sql, $_sess_db);
}

session_set_save_handler('open', 'close', 'read', 'write','destroy','clean');

session_start();

Edited by d3rck: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.