dongxing4196 2015-02-15 23:10
浏览 32
已采纳

查找自上次访问index.php以来的时间,小部件

I've done a fair amount of searching on the internet to find a solution to this issue; however, I am still unable to find a real answer.

I would like to have a widget on my site that shows the user how long in seconds it has been since someone last visited the website. For example the clock would reset to '0' if someone were the refresh the page.

Not to be be confused with the time since a specific individual last visited the site, I'm asking to find the time since ANYONE sent a request for index.php .

I assume the way to do this is tied up in a large amount of PHP, of which I am not great at. Any help, advice or pointers anyone could give would be great! Many thanks in advance.

Lastly to prevent more confusion the clock does not need to be live on the browser. It would just change each time the page is reloaded.

  • 写回答

1条回答 默认 最新

  • duanbinmi8970 2015-02-15 23:17
    关注

    The best way to (as you said in your question) find the time since ANYONE sent a request for index.php is as follows:

    Make a little viewer.txt file where you store the last timestamp information, and overwrite it with the function time() of the latest user visit in unix seconds, as follows. Then compare with the current time, on another file. (This method is much easier than sockets, and resembles a little database). I've programmed this code for you, put it on the page that you wish. It's completely functional, and I have tested it:

    File 1 (tracking and storing latest user visit):

    <?php
    
    $file = fopen("viewer.txt", "w");
    
    fwrite($file, "".time()."");
    
    fclose($file);
    
    ?>
    

    File 2 (comparing current time with last user visit):

    <?php
    
    $file = file_get_contents("viewer.txt");
    
    $file = (int)$file;
    
    echo "Difference in time from last visit in seconds:";
    
    echo $file - time();
    
    ?>
    

    Mark this answer with the checkmark on the side of it if it helped.

    Feel free to ask for more of my help if you have more questions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失