You are here

function sess_read in Memcache API and Integration 5

Same name and namespace in other branches
  1. 5.2 session-memcache.inc \sess_read()
  2. 5.2 session-memcache-db.inc \sess_read()
  3. 5.2 session-memcache.db.inc \sess_read()
  4. 6 memcache-session.inc \sess_read()

File

./memcache-session.inc, line 27
User session handling functions.

Code

function sess_read($key) {
  global $user;

  // Write and Close handlers are called after destructing objects since PHP 5.0.5
  // Thus destructors can use sessions but session handler can't use objects.
  // So we are moving session closure before destructing objects.
  register_shutdown_function('session_write_close');

  // Handle the case of first time visitors and clients that don't store cookies (eg. web crawlers).
  if (!isset($_COOKIE[session_name()])) {
    $user = drupal_anonymous_user();
    return '';
  }

  // Otherwise, if the session is still active, we have a record of the client's session in memcache.
  $session = dmemcache_get($key, 'session');
  $user = sess_user_load($session);
  return $user->session;
}