简体   繁体   中英

Log user login time with php and show it on website

I have a question about saving the moment a person logged in on my website. Let's say User John logged into my website on 17 January 2018 time: 16:24.

I want to put that date in my footer on my website, but how?

Is there a just a simple way with a PHP function?

Example:

John - Logged in sice 17 January 2018 16:24

when user logs in, set the time in session :

$_SESSION['logged_in_datetime'] = date("d M Y H:i");

and then, if you want to just display it and do not want to query the db,

<?php 
echo $_SESSION['username']."  - Logged in since ".$_SESSION['logged_in_datetime'];
?>

It is a simple sql query. You should have a datetime type field in your database table and you can query the user and show the last logged time value.

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