Jump to content

[SOLVED] Last active


tauchai83

Recommended Posts

Well, I have a login page that would like to track the last login page of the user. When their login is succeed, I will update the table and set it to NOW() which work well and save into DB.

 

My problem is I would like to display the last login datetime to the user. ie, Your last login was. $date

 

But since I update each time user login, they will get the same date as they are logging now. Should i add another column? Please guide me. Thank you!  :)

Link to comment
https://forums.phpfreaks.com/topic/38290-solved-last-active/
Share on other sites

if( strcmp( $ValidPassword[1], $txtPassword) == 0 )

{

$complete = 1;

            $userid = $txtUserID;

session_register('userid');

$HTTP_SESSION_VARS['userid'] = $userid;

            $sql="UPDATE customer SET Last_active=NOW() WHERE Cust_id='$userid'";

            $result=mysql_query($sql);

 

............

............

 

I want the user see their own last login date. If Admin see, it's easy because I can just retrive from DB. But for user themselve, once they login, the date already updated, so when i retrive, I'll get the updated date. I have a Last_active coloumn in my DB. I wonder if there is a need to add one more colomn called Current_active_date.Any idea?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/38290-solved-last-active/#findComment-183508
Share on other sites

Okay so why don't you just set a session variable called 'last_login' with the login time/date from the database when you validate their password BEFORE updating your record to reflect the current login time.

 

 

if( strcmp( $ValidPassword[1], $txtPassword) == 0 )
{
   $complete = 1;
             $userid = $txtUserID;
   //Get Last Login Time From DB Here
   //Set Session Variable 'last_login' here
  //Then Continue On With Database Update To Reflect Current Login Time
   session_register('userid');
   $HTTP_SESSION_VARS['userid'] = $userid;
             $sql="UPDATE customer SET Last_active=NOW() WHERE Cust_id='$userid'";
             $result=mysql_query($sql);

Link to comment
https://forums.phpfreaks.com/topic/38290-solved-last-active/#findComment-183517
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.