function services_session_load in Services 7
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()
- 6.2 services.module \services_session_load()
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
1 call to services_session_load()
- _services_keyauth_authenticate_call in auth/
services_keyauth/ services_keyauth.inc
File
- ./
services.module, line 639 - @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
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;
}
// Prevent saving of this impersonation in case of unexpected failure.
session_save_session(FALSE);
return $backup;
}