嘿伙计们,我正在我的网站上运行一个脚本:当用户登录我的网站时,我将这一天的日期写入一个文本文件,这样我就可以知道用户在我的网站上处于活跃状态。问题是,如果用户说没有从网站注销 2 天或更长时间,我如何检查他在那几天是否在网站上?有人可以给我一个好的建议吗?
这是我作为登录的一部分运行的代码,就在我注册会话之前:(顺便说一句,我很高兴听到是否有更好的方法来做到这一点?)
$log_file_name = "logfile.txt";
$log_file_path = "log_files/$id/$log_file_name";
if(file_exists($log_file_path)){
$not = "";
$todaydate = date('d,m,Y');
$today = "$todaydate;";
$strlength = strlen($today);
$file_contents = file_get_contents($log_file_path);
$file_contents_arry = explode(";",$file_contents);
if(!in_array($todaydate,$file_contents_arry)){
$append = fopen($log_file_path, 'a');
$write = fwrite($append,$today); //writes our string to our file.
$close = fclose($append); //closes our file
}
else if(in_array($todaytodaydate,$file_contents_arry)){}
}
else{
mkdir("log_files/$id", 0700);
$todaydate = date('d,m,Y');
$today = "$todaydate;";
$strlength = strlen($today);
$create = fopen($log_file_path, "w");
$write = fwrite($create, $today, $strlength); //writes our string to our file.
$close = fclose($create); //closes our file
}