You are here

function services_session_unload in Services 7

Same name and namespace in other branches
  1. 5 services.module \services_session_unload()
  2. 6.3 services.runtime.inc \services_session_unload()
  3. 6 services.module \services_session_unload()
  4. 6.2 services.module \services_session_unload()

Revert to previously backuped session. @TODO this function needs to be looked at much closely to use drupals new session handling stuff

1 call to services_session_unload()
services_session_load in ./services.module
Backup current session data and import user session. @TODO this function needs to be looked at much closely to use drupals new session handling stuff

File

./services.module, line 678
@author Services Dev Team

Code

function services_session_unload($backup) {
  global $user;

  // No point in reverting if it's the same user's data
  if ($user->sid == $backup->sid) {
    return;
  }

  // Some client/servers, like XMLRPC, do not handle cookies, so imitate it to make sess_read() function try to look for user,
  // instead of just loading anonymous user :).
  if (!isset($_COOKIE[session_name()])) {
    $_COOKIE[session_name()] = $backup->sessid;
  }

  // Save current session data
  sess_write($user->sid, session_encode());

  // Empty current session data
  $_SESSION = array();

  // Revert to previous user and session data
  $user = $backup;
  session_id($backup->sessid);
  session_decode($user->session);
  session_save_session(TRUE);
}