Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Last time user visited/logged in
Old 12-16-2005, 01:23 PM Last time user visited/logged in
Novice Talker

Posts: 8
Trades: 0
I want to display the last time a user visited thier account like here in the forum. It tells you when was the last time you visited.

I want display when was the last time the user logged in.

i am using PHP and MYSQL.

Any Ideas?
dmarre is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-16-2005, 01:25 PM
purk's Avatar
Extreme Talker

Posts: 164
Name: James
Location: marbella & surrey
Trades: 0
why not add a field to your members table (lastin) and do an UPDATE when they pass validation (login). i use date("d-m-y H:i:s") in mine.

;p
__________________

Please login or register to view this content. Registration is FREE
- private villas direct from the owners - travel links always needed.
purk is offline
Reply With Quote
View Public Profile Visit purk's homepage!
 
Old 12-16-2005, 01:29 PM
Novice Talker

Posts: 8
Trades: 0
I have a table called LastLogin. I do an update query when they login which updates the field with now() and it works fine. If i echo that value into the page it displays the current date an time, but when the page gets reloaded or refreshed the table get updated and then displays the new date and time.

What i need is probaly two fields in my table. One will record the current login time and the other will will record the last login time.

Example: Let say a user logged in on 12/01/2005. That date must be recorded.

Then they came back on 12/10/2005 and logged in. The last login date should display 12/01/2005 and not 12/10/2005.

when they login on 12/15/2005 the last login date should echo 12/10/2005 and so on...
dmarre is offline
Reply With Quote
View Public Profile
 
Old 12-17-2005, 04:50 AM
akratellio's Avatar
Experienced Talker

Posts: 30
Location: Berlin Germany Europe World
Trades: 0
hi dmarre,

i don't get the point...
when a user has logged in you give him the information that his
last visit was on 12.01.2005.
after that you put the new date in your database.
if you want to keep the old date in mind you can put it in the
session- or get array.
by that you can show the date of visiting during the visitors stay.

mfg
akratellio
__________________
I'm always lying...
Ich lüge immer...

Please login or register to view this content. Registration is FREE
akratellio is offline
Reply With Quote
View Public Profile Visit akratellio's homepage!
 
Old 12-17-2005, 09:37 AM
Novice Talker

Posts: 8
Trades: 0
Well the point, is this. If i create a session based on the value stored in LastLogin and echo the value i will get the date. As the page loads the rest of the code, the table gets updated with the new date.

If the user goes to another page and comes back to where it displays the last visit or refreshes the page, the php code on the page gets reloaded. What that does it creates the session variable again, keep in mind that it is getting the value from LastLogin table, then it displays the new date that was last recorded. So the actual date keeps changing if you refresh the page.

What would be nice: If i can load a session variable based on LastLogin value and say if session still exist do not change session variable, but still update the database.

What i have done: I have created a session variable to display the last time a user visited. I have placed the update code on the logout page to update the LastLogin with the now(). That is how it is working now, but if the user closes the window without login out, then it will not update.

I am not a PHP coder or master. I can think of the theory but can't code it. That is why i am asking for help. Adn i don't want to use cookies because if the user cleans out his computer, th last login date will be incorrect.

Does it make sense?
dmarre is offline
Reply With Quote
View Public Profile
 
Old 12-17-2005, 03:36 PM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
I think you missed something.

At the point of login the session last login info is created but at no other time is it created so whenever you reload a page the session info remains the same.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 12-17-2005, 08:58 PM
Novice Talker

Posts: 8
Trades: 0
So when is the table updated with the date and time?

I am not trying to be a pest, but if i wanted to figure it out i would have never posted and asked for help. Since this is a time sensitive issue, i was trying to get some code help as in <? blah blah blah ?> not a, you can do it lesson.

Thanks.
dmarre is offline
Reply With Quote
View Public Profile
 
Old 12-18-2005, 12:38 PM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
When the person hits the sign in button:
the script queries the db to find the user,
if found it takes the last login date puts it in a session variable,
then it updates the lastlogin field with the current date.

The session will have the last login time and the db will have the current login time for future reference.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 12-19-2005, 05:51 PM
Novice Talker

Posts: 8
Trades: 0
After working with this, it is finally finished. Based on reli4nt's "general advice", I came up with a "precise" method that works for me. In the logging in "if statement", i added the following "CODE". It creates a session variable to store the value of my LastLogin table.
PHP Code:
$LoginRS__query=sprintf("SELECT * FROM tablename WHERE USERNAME='%s' "get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername));

$LoginRS mysql_query($LoginRS__query$onpoint) or die(mysql_error());
$query mysql_fetch_assoc($LoginRS); //My Code 

$GLOBALS['LastLogin'] = $query['LastLogin']; //my code

 //Session variable for last login
$_SESSION['LastLogin'] = $query['LastLogin']; //My code 
This is done when the user clicks on the login button. After that they are redirected to the main page if login is successful.

In the main page I added this code to it:
PHP Code:
$query=mysql_query("UPDATE tablename SET LastLogin=now() WHERE CID='$CID'");
$result mysql_query($query); 
CID='$CID' is a session variable that is created when the page loads. It is used to update the table who's session = the $CID variable. If you had to use this just change the variable to yours and change the database table names to match your database.

What this does it updates the LastLogin table with the current date and time. So if the user closes thier browser or logs out. The next time they login, the time value that was just updated will be displayed in the main info page once they login.

Here is the code i used to echo (display) the time value when the user is redirected to the main info page after loggin in.
PHP Code:
echo date("F d, Y @ g:i a"strtotime($_SESSION['LastLogin'])); 
This code will display your date variable like this:
December 19, 2005 @ 5:02 pm

Hope this helps.
dmarre is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Last time user visited/logged in
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35926 seconds with 12 queries