简体   繁体   English

PHP检查上次用户访问页面的时间

[英]php check when last time user visited a page

I have a page login.php in which when the user login a cookie is set by the username just to ensure that if the user comes back again he need not have to log in. But now I need to specify his last visit also. 我有一个login.php页面,在该页面中,当用户登录时,使用用户username设置cookie只是为了确保如果用户再次回来,则不必登录。但是现在,我还需要指定其最后一次访问。 How shall I do that? 我该怎么办?

Login.php Login.php

if(isset($_POST["checkbox"]) && $_POST["checkbox"]==1) {
    $expire = time() + 365*24*60*60;
}else{
    $expire = 0;
}

setcookie("user", $row['username'], $expire, "/");

The above code creates a cookie by the username as soon as the user logs in. 上面的代码在用户登录后立即通过用户名创建一个cookie。

Also I have a file that checks if the user has already logged in and if 'yes' it doesn't let the user enter his credentials again. 另外,我还有一个文件,用于检查用户是否已经登录,如果是,则不允许用户再次输入其凭据。 But now I want when the user logs in a message should appear saying "you last visited the site...". 但是现在我想要当用户登录时出现一条消息,说“您上次访问该站点...”。

How to do that? 怎么做?

Add a column in db table, and after each successful login update the login date and time in it. 在db表中添加一列,并在每次成功登录后更新其中的登录日期和时间。

  • You can find the same question and answers here 您可以在 此处 找到相同的问题和答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM