Drupal – “Access Denied” user accounts orders

After a host did a PHP upgrade drupal decided not to remember sessions
very well any more. I’m still not sure what the exact problem was but
this is what fixed it…

In the file /includes/session.inc change:

function sess_write($key, $value) {
global $user;
db_query("UPDATE {sessions} SET uid = %d, hostname = '%s', session =
'%s', timestamp = %d WHERE sid = '%s'", $user->uid,
$_SERVER["REMOTE_ADDR"], $value, time(), $key);
return '';
}

to

function sess_write($key, $value) {
global $user;

if($user->uid)
db_query("UPDATE {sessions} SET uid = %d, hostname = '%s', session =
'%s', timestamp = %d WHERE sid = '%s'", $user->uid,
$_SERVER["REMOTE_ADDR"], $value, time(), $key);
else
db_query("UPDATE {sessions} SET hostname = '%s', session = '%s',
timestamp = %d WHERE sid = '%s'", $_SERVER["REMOTE_ADDR"], $value,
time(), $key);

return '';
}

Leave a Reply

Your email address will not be published. Required fields are marked *