每天跟踪用户登录

时间:2012-11-03 21:57:16

标签: php

嘿伙计们我在我的网站上运行脚本: 当用户登录我的网站时,我将今天的日期写入文本文件,这样我就可以知道用户在我的网站上活跃了。 问题是,如果用户说让我没有从网站注销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
      }

1 个答案:

答案 0 :(得分:1)

这不是文本文件要处理的东西(因为你最终会得到数百个文本文件),这应该用数据库和一组更新查询。