Hi guys, I am setting up an EC2 cluster with a load balancer. I have a separate database server running mysql. I have 3 web servers working, mainly for high availability, and of course, its load balancing seems to be why every page that you access gets a different server that is losing the session.
I am trying to configure PHP to store it in a database. I installed the table and installed all the functions (open, close, etc.). and I installed:
session_set_save_handler('_open',
'_close',
'_read',
'_write',
'_destroy',
'_clean');
But when I log in to the system or something on the site, I check the table and nothing was written. I am not sure if I need to change something in the php.ini file. If so, what is the significance of the change?
Thank!!
EDIT: functions:
function _open(){
global $con;
connect();
}
function _close(){
global $con;
}
function _read($id){
global $con;
$id = mysql_real_escape_string($id);
$sql = "SELECT data FROM sessions WHERE id = '$id'";
if ($result = mysql_query($sql, $con)) {
if (mysql_num_rows($result)) {
$record = mysql_fetch_assoc($result);
return $record['data'];
}
}
return '';
}
function _write($id, $data)
{
global $con;
$access = time();
$id = mysql_real_escape_string($id);
$access = mysql_real_escape_string($access);
$data = mysql_real_escape_string($data);
$sql = "REPLACE
INTO sessions
VALUES ('$id', '$access', '$data')";
return mysql_query($sql, $con);
}
function _destroy($id)
{
global $con;
$id = mysql_real_escape_string($id);
$sql = "DELETE
FROM sessions
WHERE id = '$id'";
return mysql_query($sql, $con);
}
function _clean($max)
{
global $con;
$old = time() - $max;
$old = mysql_real_escape_string($old);
$sql = "DELETE
FROM sessions
WHERE access < '$old'";
return mysql_query($sql, $con);
}
session_set_save_handler('_open',
'_close',
'_read',
'_write',
'_destroy',
'_clean');