Hi all , I need help on how to do a last visit update to find the previous login date and time of the user.
Need Help For Last Visit
Collapse
X
-
If this is on a system where you store the user details in a database you can also store the date and time of the visit. So when the log in again you can check when they last visited display any information you need to based on that and then log the new visit date and time.Originally posted by chaosHi all , I need help on how to do a last visit update to find the previous login date and time of the user.
This way doesn't rely on cookies which may be switched off on the user side of things.
This is the way I would do it, as the data is more permanent. Even if the user has cookies on they can clear them out so you loose the information about their last login. Storing it in the database means you have contorol over the data you need.
Cheers
nathjComment
-
Originally posted by nathjIf this is on a system where you store the user details in a database you can also store the date and time of the visit. So when the log in again you can check when they last visited display any information you need to based on that and then log the new visit date and time.
This way doesn't rely on cookies which may be switched off on the user side of things.
This is the way I would do it, as the data is more permanent. Even if the user has cookies on they can clear them out so you loose the information about their last login. Storing it in the database means you have contorol over the data you need.
Cheers
nathj
wt will be the code like???Comment
-
Hi,Originally posted by chaoswt will be the code like???
First of all you need a database with a table in it that stores the user credentials.
Second you need a login page. This normally includes a form with a post method. The desitination page, as set by the action on the form, would check the credentials entered are for a valid user and if so when they last logged in. If the credentials are invalid then you need to report in this to the visitor.
Third, based on the the current time and the last logged in time the user who sucesfully logs in can be presented with a specific message. This would go on the the page the login form specifies as the form action.
That's the general principle. I will be doing something like this very shortly but that the design I have mapped out. I am not going to write my module and then give you the code, however if you have a go and post any code you get stuck with I will help out.
It is worth reading through some tutorials on php and database:
Data Abstraction Layer
W3Schools
These are both excellent, I use them all the time.
Cheers
nathjComment
-
A quick way is to make your user table have two more columns for the latest login time and the last login time. Then, you could update it simply whenever users log on:
[code=php]mysql_query("UP DATE `user` SET `lastLogin` = `latestLogin`, `latestLogin` = " . date('Y-m-d H:i:s') . " WHERE `username` = '" . $username . "' AND `password` = '" . $password . "';");
if(mysql_affect ed_rows())
{
// login credentials were correct
}[/code]Comment
-
In if(mysql_affect ed_rows())Originally posted by volectricityA quick way is to make your user table have two more columns for the latest login time and the last login time. Then, you could update it simply whenever users log on:
[code=php]mysql_query("UP DATE `user` SET `lastLogin` = `latestLogin`, `latestLogin` = " . date('Y-m-d H:i:s') . " WHERE `username` = '" . $username . "' AND `password` = '" . $password . "';");
if(mysql_affect ed_rows())
{
// login credentials were correct
}[/code]
{
// login credentials were correct
}
wt should i put for the login credentialsComment
Comment