Website showing - 31 Dec, 1969 18:00:00 ()

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,153
Reaction score
10,492
On one page on my site there's a section that shows: "You were last logged in on 31 Dec, 1969 18:00:00 ()."

The date should be updated according to the date/time the user was last logged in.

Here's the code in the php file responsible for this:

PHP:
<?php
   echo(ucfirst($user->GetData('UserFirstName').' '));
   echo(ucfirst($user->GetData('UserLastName')));

   $UserID = $user->GetData('UserID');

   $stmt = $pdo->prepare('SELECT * FROM Logs WHERE LogUserID = :LogUserID ORDER BY LogID DESC LIMIT 1');
   $stmt->bindParam(':LogUserID', $UserID);
   $stmt->execute();

   $row = $stmt->fetch(PDO::FETCH_ASSOC);
   $login_date = $row['LogDate'];
   $login_ip_address = $row['LogIPAddress'];
?>
</h1>
<span class="text-muted">
   <p>Welcome back, <?php echo(ucfirst($user->GetData('UserName'))); ?>.</p>
   <br>
   <p>You were last logged in on <b><?php echo(date('d M, Y H:i:s', $login_date)) ?></b> (<b><?php echo($login_ip_address); ?></b>).</p>

</span>

Can anyone help me fix this?

Thank you
 
That isn't the right piece of code.

You see, there's a date function which takes 2 parameters, first one is the format of date text and second one is timestamp.

31/12/1969 is the date when timestamp count starts, i.e. at this date timestamp was 0.

Now this means you don't save the timestamp properly somewhere else and it always returns 0 from mysql (or false, whatever)

Check the piece of code somewhere around login funcitonality, it is the real problem :)
 
What is the value of $login_date? << It's probably not the right format to pass to date()
 
Is value in the DB that you are pulling out right? Check up on that.

Frankly, I'm no expert with coding stuff.

I checked the databases, and one database called "Logs," has logs of every login, and when I open any of the listings there there's this that may be relevant:

Column-------Type----------Value
LogDate----int(244)----1491857567

Is that what you're asking for?
 
On one page on my site there's a section that shows: "You were last logged in on 31 Dec, 1969 18:00:00 ()."

That is a long time between logins... did you forget you had that site?
 
That isn't the right piece of code.

You see, there's a date function which takes 2 parameters, first one is the format of date text and second one is timestamp.

31/12/1969 is the date when timestamp count starts, i.e. at this date timestamp was 0.

Now this means you don't save the timestamp properly somewhere else and it always returns 0 from mysql (or false, whatever)

Check the piece of code somewhere around login funcitonality, it is the real problem :)

Thanks for the explanation.

I looked through Login.php, and maybe this piece of code is relevant?

PHP:
if($stmt->rowCount() > 0) {
                            $stmt = $pdo->prepare('SELECT * FROM users WHERE UserName = :UserName AND UserPassword = :UserPassword');
                            $stmt->execute(array(':UserName' => $username, ':UserPassword' => $password));
                            
                            if($stmt->rowCount() > 0) {
                                $row = $stmt->fetch();
                                $UserLevel = $row['UserLevel'];
                                
                                if($UserLevel == 'banned') {
                                    $display->ReturnError('Your account has been suspended.');
                                    return false;
                                }
                                $UserID = $row['UserID'];
                                $time = time();
                                $IPAddress = $_SERVER['REMOTE_ADDR'];
                                
                                $_SESSION['auth'] = $UserID;
                                
                                $stmt = $pdo->prepare('INSERT INTO logs (LogUserID, LogDate, LogIPAddress) VALUES (:LogUserID, :LogDate, :LogIPAddress)');
                                $stmt->execute(array(':LogUserID' => $UserID, ':LogDate' => $time, ':LogIPAddress' => $IPAddress));
                                
                                $display->ReturnSuccess('You was successfully logged in.');
                                $settings->forceRedirect('index.php', 2);
                            } else {
                                $display->ReturnError('Invalid user credentials.');
                            }
                        } else {
                            $display->ReturnError('User with these credentials does not exists.');
                        }
                    }
                }
            ?>
        </div>
 
Frankly, I'm no expert with coding stuff.

I checked the databases, and one database called "Logs," has logs of every login, and when I open any of the listings there there's this that may be relevant:

Column-------Type----------Value
LogDate----int(244)----1491857567

Is that what you're asking for?

Yes that seems right. IP is there as well I guess.

Where can I find the value of $login_date?

Its the value listed above :)

It seems to me that you are not pulling it out from DB right. Are there any error_logs? Is connection for that single file to mysql good or this is your entire file?
 
You must not be getting the "LogDate" value correctly from your database.

Check what this returns:
<?php print_r($login_date); ?>

I hope this is what you meant...

I turned this:

PHP:
<p>You were last logged in on <b><?php echo(date('d M, Y H:i:s', $login_date)) ?></b> (<b><?php echo($login_ip_address); ?></b>).</p>

To this:

PHP:
<p>You were last logged in on <b><?php print_r($login_date); ?> </b> (<b><?php echo($login_ip_address); ?></b>).</p>

And on the site it now shows: "You were last logged in on ()."
 
Yes that seems right. IP is there as well I guess.



Its the value listed above :)

It seems to me that you are not pulling it out from DB right. Are there any error_logs? Is connection for that single file to mysql good or this is your entire file?

Well... actually there's a section on the site where I can see "Logs," and there the "Logged Date" is correct.

But my problem with the date is on the Profile (Profile.php) page. So it's not a universal problem for the entire site, but only for that bit on that page.

Now, on the "Logs" section I mentioned, this should be the code for it (on the logs page dates are shown correctly):

PHP:
foreach($stmt->fetchAll() as $row) {
                                                                                $UserName = $user->GetDataID($row['LogUserID'], 'UserName');
                                                                               
                                                                                $html = '<tr>';
                                                                                $html .= '<th class="numeric">'.$row['LogID'].'</th>';
                                                                                $html .= '<th>'.$UserName.'</th>';
                                                                                $html .= '<th>'.date('d.m.Y H:i', $row['LogDate']).'</th>';
                                                                                $html .= '<th>'.$row['LogIPAddress'].'</th>';
                                                                                $html .= '</tr>';
                                                                               
                                                                                echo $html;

Does that help?
 
hmm.. can your profile.php page actually connect to the database?

The database connection is probably done in a separate file somewhere (don't post this online for obvious reasons).
 
hmm.. can your profile.php page actually connect to the database?

The database connection is probably done in a separate file somewhere (don't post this online for obvious reasons).

Could be...

This is beyond me. I think I'll just remove that bit and write some text for users. I mean, what do users even care about the last time they were logged in and their IP at that time. I don't think that's important to anyone.

Thanks everyone for trying to help. Much appreciated :)
 
No problem, I can probably fix it though if I could have a look at that logs file where the date does work. Just PM me if you need any more help (free of course before people start whining about advertising or w/e) ;)
 
No problem, I can probably fix it though if I could have a look at that logs file where the date does work. Just PM me if you need any more help (free of course before people start whining about advertising or w/e) ;)

Thanks man. I'm good about this. Much appreciated :)
 
"Hey, let's go check out the internet!"
delorean.jpg
 
Back
Top