You are here

function sess_regenerate in Memcache API and Integration 5.2

Same name in this branch
  1. 5.2 session-memcache.inc \sess_regenerate()
  2. 5.2 session-memcache-db.inc \sess_regenerate()
  3. 5.2 session-memcache.db.inc \sess_regenerate()
Same name and namespace in other branches
  1. 5 memcache-session.inc \sess_regenerate()
  2. 6 memcache-session.inc \sess_regenerate()

Called when an anonymous user becomes authenticated or vice-versa.

File

./session-memcache-db.inc, line 108
User session handling functions.

Code

function sess_regenerate() {
  $old_session_id = session_id();

  // We code around http://bugs.php.net/bug.php?id=32802 by destroying
  // the session cookie by setting expiration in the past (a negative
  // value).  This issue only arises in PHP versions before 4.4.0,
  // regardless of the Drupal configuration.
  // TODO: remove this when we require at least PHP 4.4.0
  if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time() - 42000, '/');
  }
  session_regenerate_id();
  $key = session_id();

  // Grab the user's information that is cached with the anonymous key
  $info = dmemcache_get($old_session_id, 'session');
  if ($info) {

    // Update it.
    $info->sid = $key;

    // Store it with the new key.
    dmemcache_set($key, $info, ini_get('session.gc_maxlifetime'), 'session');

    // Clear the old data from the cache.
    dmemcache_delete($old_session_id, 'session');
  }

  //Always keep the db synced with memcache in case of failure
  db_query("UPDATE {sessions} SET sid = '%s' WHERE sid = '%s'", $key, $old_session_id);
}