Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:01:37+00:00 2026-05-25T23:01:37+00:00

I have this on my login page: $current_time = date("g:i A"); $current_date = date("l,

  • 0

I have this on my login page:

   $current_time = date("g:i A");
   $current_date = date("l, F jS, Y");
   mysql_query("UPDATE employees 
   SET last_login = '$current_time', last_login_date = '$current_date' WHERE username='$username' AND password='$password'");

And then on the page when the user is logged in (the protected page) I have this:

 [...]

 <?php 
 $last_login_date = $info['last_login_date']; // get last_login_date from mysql table
 $last_login_time = $info['last_login_time']; // get last_login_time from mysql table
 ?>

 [...]

 You last signed in on <?php echo $last_login_date; ?> at <?php echo $last_login_time; ?>.

But this doesn’t work properly because it shows the time they just logged in. How can I make it show the last time they logged in?

I also even tried adding a prev_login_time and prev_login_date to the table too, but I don’t know how to make it update properly because it would update every time they login making it show the time they just logged in. (so it would be showing the current time to them)

Thanks.


Edit: [for EdoDodo]

Here’s the login if statement that is setting the last IP address session variable:

if($_POST['submit']) {
$sql = "SELECT * FROM employees WHERE username='$username' and password='$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$info = mysql_fetch_array($result);

     if($count == 1) {

     $_SESSION['loggedin'] = 1;
     $_SESSION['user'] = $username;
     $_SESSION['last_login_time'] = $info['last_login'];
     $_SESSION['last_login_date'] = $info['last_login_date'];
     $_SESSION['last_ip'] = $info['last_login_ip'];
     
         $return = $_SESSION['returnurl'];
         if(!$return) {
         $return = "/employee/";
         }
         date_default_timezone_set('America/New_York');
         $current_time = date("g:i A");                                                                                                                                                                                       
         $current_date = date("l, F jS, Y");
         $ip = $_SERVER['REMOTE_ADDR'];
         mysql_query("UPDATE employees 
         SET last_login = '$current_time', last_login_date = '$current_date', last_login_ip = '$ip' WHERE username='$username' AND password='$password'");
         header("Location: $return");
         exit();
     } 

The last login date and time is working, which is why I don’t know why it isn’t working with the IP one. I am accessing it correctly on the protected page:

$last_login_date = $_SESSION['last_login_date'];
    if($last_login_date = date("l, F jS, Y")) {
    $last_login_date = "Today";
    }
    $last_login_time = $_SESSION['last_login_time'];
    if($_SESSION['last_ip'] != $_SERVER['REMOTE_ADDR']) {
    $last_login_ip = "this IP address (".$_SERVER['REMOTE_ADDR'].")";
    }
    else {
    $last_login_ip = "IP address ".$_SESSION['last_ip'];
    }                                                                                                                
    echo "Last account login: ".$last_login_date." at " . $last_login_time . " from " . $last_login_ip . ".";

Am I doing something wrong? Maybe I’m not setting the session variable or retrieving it properly? But it seems like I am. I hope you can help. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:01:37+00:00Added an answer on May 25, 2026 at 11:01 pm

    You’ll want to fetch the login time from the table in the database into the $info array before you update the database and overwrite the time with the new one. Then, you’ll have the previous login time in the $info array (and, if you want to carry it across lots of different page loads, you could put it in a session variable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation: There are a login page with a login form (form
i have this page . login: fer password: m Note: after login you will
Currently, in my settings module I have this: LOGIN_URL = '/login' If I ever
i have this chatbox, and when users login i want it to send a
I have a login form for my website. This login form have two text
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
I have this authnav='<li class=last><a href=auth/login>login</a></li>'+ '<li><a href=auth/create_account>create account</a></li>'; It works fine in Firefox,
I have a login screen that I force to be ssl, so like this:
I have one image submit button like this <input id=enter name=enter type=image value=Login src=images/btn_login.jpg/>
I have a simple GAE app that includes a login/logout link. This app is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.