0
我有以下代碼:如何計算過去24小時的訪客?
$ips = file_get_contents($_SERVER['DOCUMENT_ROOT']."/visitors.txt");
$arr = explode(",",$ips);
$today = strtotime(date('Y-m-d H:i:s'));
for ($n = 0, $max = count($arr); $n <= $max; $n++) {
$visArr = explode("#",$arr[$n]);
$visDate = strtotime($visArr[1]); //$visArr[1] = 2011-12-27 14:10:45
if($visDate < $today){
unset ($arr[$n]); //remove array item if its date not within 24 hours
}
}
的數據存儲這樣的:
xxx.xxx.xxx.xxx#2011-12-27 11:56:24,
xxx.xxx.xxx.xxx#2011-12-28 11:56:24,
我想從過去24小時所獲得的訪問者。
我不想使用MySQL數據庫,我只是想使用txt文件,但我卡住了。
在此先感謝。
重複http://stackoverflow.com/questions/8670262/wrong-in-date-comparison – liquorvicar 2011-12-31 10:24:18