You are here

function services_session_load in Services 5

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

Backup current session data and import user session.

1 call to services_session_load()
services_method_call in ./services.module
This is the magic function through which all remote method calls must pass.

File

./services.module, line 601
The module which provides the core code for drupal services

Code

function services_session_load($sessid) {
  global $user;

  // If user's session is already loaded, just return current user's data
  if ($user->sid == $sessid) {
    return $user;
  }

  // Make backup of current user and session data
  $backup = $user;
  $backup->session = session_encode();

  // Empty current session data
  foreach ($_SESSION as $key => $value) {
    unset($_SESSION[$key]);
  }

  // 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()] = $sessid;
  }

  // Load session data
  session_id($sessid);
  sess_read($sessid);

  // Check if it really loaded user and, for additional security, if user was logged from the same IP. If not, then revert automatically.
  if ($user->sid != $sessid) {
    services_session_unload($backup);
    return NULL;
  }
  return $backup;
}