0
我已经创建了我自己的会话,现在想超时非活动用户。事情是我已经得到它的工作..有点......在会话超时已过,当我点击另一个页面时,它什么都没做,但是当我再次点击某个事物时,它按照应该的时间超时。下面是我的代码定时会话与非活动帐户
if(preg_match("#^" . DOMAIN_SSL . ".*#is", $_SERVER['HTTP_REFERER'])) {
# connect to main database that holds all accounts
$con = mysql_connect('##########', '#########', '############') or die (mysql_error());
$db = mysql_select_db('##########', $con);
# find data which is identified via KI
$query = mysql_query("SELECT * FROM `accounts` WHERE KI = '$KI' ", $con) or die ("error: " . mysql_error());
# if KI is not found
if(mysql_num_rows($query) != 0) {
$array = mysql_fetch_array($query);
mysql_query("UPDATE `accounts` SET timelog = '" . time() . "' WHERE KI = '$KI' ", $con) or die ("error: " . mysql_error());
# get account information and create a group of constants
define("USER_PASS", $array['password']);
define("USER_EMAIL", $array['email']);
define("USER_DOMAIN", $array['website']);
define("USER_FIRST_NAME", $array['fname']);
define("DB_USER", $array['db_name']);
define("DB_PASS", $array['db_pass']);
define("DB_HOST", 'localhost');
define("FTP_USER", $array['ftpuser']);
define("FTP_PASS", $array['ftppass']);
define("FTP_SERVER", $array['ftpserver']);
define("MD5_WEBSITE", trim(md5($array['website'])));
define("ROOT_FOLDER", $array['rootfolder']);
define("TIMELOG", $array['timelog']);
define("EDITOR", $array['editor']);
# begin to set new KI
$time = TIMELOG/60; #return timein minutes
$time = floor($time/TIMEOUT);
$NEW_KI = md5($_SERVER['REMOTE_ADDR'] . USER_EMAIL . USER_PASS . $time);
mysql_query("UPDATE `accounts` SET KI = '$NEW_KI' WHERE KI = '$KI' ", $con) or die ("error: " . mysql_error());
if(strcmp ($NEW_KI, $KI) == 0) {
# update KI to reset 15 min timeout
define("KI", $NEW_KI);
# continue to load pages - success!
$USER_CON = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$USER_db = mysql_select_db(DB_USER, $USER_CON);
}else{
#close open mysql connection
mysql_close($con);
# produce timeout error message - failed!
header("location: " . DOMAIN . "?e=7");
}
}else{
#close open mysql connection
mysql_close($con);
# produce timeout error message - failed!
header("location: " . DOMAIN . "?e=7");
}
}
所有页面都会通过存储的一个主页面运行。 $ KI通过GET var传递。 任何帮助,为什么这是这样做,将不胜感激。