function _autologout_invalidate_other_sessions in Automated Logout 7.2
Same name and namespace in other branches
- 6.2 autologout.module \_autologout_invalidate_other_sessions()
1 call to _autologout_invalidate_other_sessions()
- autologout_user_login in ./autologout.module
- Implements hook_user_login().
File
- ./autologout.module, line 545
- Used to automagically log out a user after a preset time, AjK May 2006
Code
function _autologout_invalidate_other_sessions($account) {
if ($account->uid == 0) {
return;
}
$result = db_select('sessions', 'ss')
->fields('ss')
->condition('ss.uid', $account->uid)
->condition('ss.sid', session_id(), '<>')
->countQuery()
->execute()
->fetchField();
if ($result != 0) {
drupal_set_message(t('You are only allowed 1 open session at a time. Your other session has been terminated.'), 'error');
$other_session_msg = t('You have been automatically logged out. You are only allowed 1 open session at a time, and another open session was detected.');
$other_session_msg = 'messages|' . serialize(array(
'error' => array(
$other_session_msg,
),
));
db_update('sessions')
->fields(array(
'uid' => '0',
'session' => $other_session_msg,
))
->condition('uid', $account->uid, '=')
->condition('sid', session_id(), '<>')
->execute();
watchdog('Automated Logout', 'One Session automatically logged out user.', array(), WATCHDOG_WARNING);
}
}