function autologout_init in Automated Logout 6.3
Same name and namespace in other branches
- 6.4 autologout.module \autologout_init()
- 6.2 autologout.module \autologout_init()
- 7.2 autologout.module \autologout_init()
- 7.4 autologout.module \autologout_init()
Implementation of hook_init().
File
- ./
autologout.module, line 71 - Used to automagically log out a user after a certain time.
Code
function autologout_init() {
global $user;
global $base_root;
if ($user->uid > 0) {
// See if automatic logout is enabled.
$seconds = variable_get('autologout_seconds', 0);
if ($seconds > 0) {
// Check the session's last access.
if (!isset($_SESSION['autologout_lastaccess']) || (int) $_SESSION['autologout_lastaccess'] > time() - $seconds) {
// Update the session's last access.
$_SESSION['autologout_lastaccess'] = time();
drupal_set_html_head("<meta http-equiv='refresh' content='{$seconds}';url='{$base_root}'>");
}
else {
// Force the user to log out.
// code from core(user.pages.inc), can't use it directly because we need need a custom goto
watchdog('user', 'Session closed for %name.', array(
'%name' => $user->name,
));
// Destroy the current session:
session_destroy();
// Only variables can be passed by reference workaround.
$null = NULL;
user_module_invoke('logout', $null, $user);
// Load the anonymous user
$user = drupal_anonymous_user();
drupal_goto('autologout/logout');
}
}
}
}