function masquerade_init in Masquerade 7
Same name and namespace in other branches
- 5 masquerade.module \masquerade_init()
- 6 masquerade.module \masquerade_init()
Implements hook_init().
File
- ./
masquerade.module, line 52 - The masquerade module allows administrators to masquerade as other user.
Code
function masquerade_init() {
global $user;
// Try to load masqing uid from masquerade table.
$uid = db_query("SELECT uid_from FROM {masquerade} WHERE sid = :sid AND uid_as = :uid_as", array(
':sid' => session_id(),
':uid_as' => $user->uid,
))
->fetchField();
// We are using identical operator (===) instead of equal (==) because if
// $uid === 0 we want to store the session variable. If there's no record in
// masquerade table we clear the session variable.
if ($uid === FALSE) {
if (isset($_SESSION)) {
unset($_SESSION['masquerading']);
}
}
else {
$_SESSION['masquerading'] = $uid;
}
}