简体   繁体   中英

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. How shall I do that?

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.

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.

  • You can find the same question and answers here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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