function services_session_load in Services 6.2
Same name and namespace in other branches
- 5 services.module \services_session_load()
- 6.3 services.runtime.inc \services_session_load()
- 6 services.module \services_session_load()
- 7 services.module \services_session_load()
Backup current session data and import user session.
Parameters
$sessid: Session ID of the session to be loaded.
Return value
Object containing current session data, which can be reloaded later in services_session_unload().
1 call to services_session_load()
- _services_keyauth_authenticate_call in auth/
services_keyauth/ services_keyauth.inc - Authenticate a services method call with key authentication.
File
- ./
services.module, line 844 - Provides a generic but powerful API for exposing web 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
$_SESSION = array();
// 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 the user.
if (!isset($user->sid) || isset($user->sid) && $user->sid != $sessid) {
services_session_unload($backup);
return NULL;
}
// Prevent saving of this impersonation in case of unexpected failure.
session_save_session(FALSE);
return $backup;
}