I am trying to force log out an inactive user from my CMS. The timeout value is stored in a value called PREF_TIMEOUT in my database. Ive borrowed this code and modified it a little. The code does not seem to be doing anything. Does anyone know of a better method of doing this or can spot what is breaking it?
<?php
function init() {
parent:: init();
self::logoutInactiveUser();
}
$timeout = mysql_query("SELECT PREF_TIMEOUT FROM preferences WHERE PREF_ID = '1'");
$result = mysql_fetch_array($timeout);
function logoutInactiveUser() {
$inactivityLimit = $timeout * 60; // Converted to seconds
$sessionStart = Session::get('session_start_time');
if (isset($sessionStart)){
$elapsed_time = time() - Session::get('session_start_time');
if ($elapsed_time >= $inactivityLimit) {
$member = Member::currentUser();
if($member) $member->logOut();
Session::clear_all();
Director::redirect(Director::baseURL() . 'Security/login');
}
}
Session::set('session_start_time', time());
}
?>