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

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.