Messages 'Cannot find session record x for user x, creating new session.'

Re: Messages 'Cannot find session record x for user x, creating new session.'

by Alain Raap -
Number of replies: 0
Picture of Particularly helpful Moodlers
Thanks Howard for your explanation. I checked the code that throws the error and thought it might be a problem,
this is the code snippet of lib/classes/session/manager.php I found:

*
* @param bool $newsid is this a new session in first http request?
*/
protected static function initialise_user_session($newsid) {
global $CFG, $DB;

$sid = session_id();
if (!$sid) {
// No session, very weird.
error_log('Missing session ID, session not started!');
self::init_empty_session();
return;
}

if (!$record = $DB->get_record('sessions', array('sid'=>$sid), 'id, sid, state, userid, lastip, timecreated, timemodified')) {
if (!$newsid) {
if (!empty($_SESSION['USER']->id)) {
// This should not happen, just log it, we MUST not produce any output here!
error_log("Cannot find session record $sid for user ".$_SESSION['USER']->id.", creating new session.");
}
// Prevent session fixation attacks.
session_regenerate_id(true);
}
$_SESSION = array();
}
unset($sid);