You are here

function services_session_unload in Services 6.3

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

Revert to previously backuped session.

1 call to services_session_unload()
services_session_load in ./services.runtime.inc
Backup current session data and import user session.

File

./services.runtime.inc, line 390
Contains functions that only are necessary when a service call is made. This has broken out so that this code isn't loaded for every page load.

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 :).
  $session_name = session_name();
  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);
}