Line 44 of session.inc is

<?php
    $user = drupal_anonymous_user($user->session);
?>

However, in situations where $user->session is not set there is an error thrown ("Trying to get property of non-object"). Because the query to establish $user has failed (as it should), $user is not yet an object. So now we do

<?php
    $session = isset($user->session) ? $user->session : '';
    $user = drupal_anonymous_user($session);
?>
CommentFileSizeAuthor
nosessjv.patch630 bytesjvandyk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

profix898’s picture

Marked http://drupal.org/node/91004 (by stefano73 a few hours ago) as duplicate of this one.

stefano73’s picture

Why not set $session to session_id() (or $key) when $user->session is not set?

profix898’s picture

I guess, because in function drupal_anonymous_user($session = '') { ..} the default value is '' already!? Does it make any difference? Any advantage setting it to session_id()?

How can spawn a situation where this patch is needed? I tried to truncate the 'session' table but that seems not enough!
I will try to reproduce/review and comment back soon.

profix898’s picture

Status: Needs review » Reviewed & tested by the community

"Why not set $session to session_id()"

  1. The content of session is a serialized array of session variables, so it it doesnt make sense to simply store a string.
  2. It doesnt make sense either to store the session id in the session itself. You can always call session_id(), if you need it, not?

To reproduce one needs a session cookie in the browser, otherwise if (!isset($_COOKIE[session_name()])) { $user = drupal_anonymous_user(); ... } simply returns with a (new) 'anonymous' user. The use case of this patch is e.g. when the user session has expired.

Patch is simple and solved the issue.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)