function services_session_load in Services 6
Same name and namespace in other branches
- 5 services.module \services_session_load()
- 6.3 services.runtime.inc \services_session_load()
- 6.2 services.module \services_session_load()
- 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 532 - @author Services Dev Team
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
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 or $user->hostname != $backup->hostname) {
services_session_unload($backup);
return NULL;
}
// Prevent saving of this impersonation in case of unexpected failure.
session_save_session(FALSE);
return $backup;
}