1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'General Programming Chat' started by Scorpion Ghost, Apr 10, 2017.

  1. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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
     
  2. littlewebdragon

    littlewebdragon Jr. VIP Jr. VIP

    Joined:
    Dec 30, 2007
    Messages:
    1,671
    Likes Received:
    826
    Occupation:
    Occupation
    Location:
    Location
    Is value in the DB that you are pulling out right? Check up on that.
     
    • Thanks Thanks x 1
  3. Mr.Nick..

    Mr.Nick.. Regular Member

    Joined:
    Sep 17, 2012
    Messages:
    240
    Likes Received:
    109
    Location:
    Georgia, Tbilisi
    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 Thanks x 1
  4. teysuro

    teysuro Registered Member

    Joined:
    Sep 19, 2012
    Messages:
    62
    Likes Received:
    16
    Gender:
    Male
    Location:
    Netherlands
    What is the value of $login_date? << It's probably not the right format to pass to date()
     
    • Thanks Thanks x 1
  5. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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?
     
  6. BassTrackerBoats

    BassTrackerBoats Super Moderator Staff Member Moderator Jr. VIP

    Joined:
    Mar 10, 2010
    Messages:
    15,927
    Likes Received:
    29,260
    Occupation:
    Selling CPA Sites
    Location:
    Not England
    Home Page:
    That is a long time between logins... did you forget you had that site?
     
    • Thanks Thanks x 1
  7. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    hehe no. I'm just setting the site up using a template I had. And I'm hustling through it to make things work and all :)
     
    • Thanks Thanks x 1
  8. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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>
     
  9. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    Where can I find the value of $login_date?
     
  10. teysuro

    teysuro Registered Member

    Joined:
    Sep 19, 2012
    Messages:
    62
    Likes Received:
    16
    Gender:
    Male
    Location:
    Netherlands
    You must not be getting the "LogDate" value correctly from your database.

    Check what this returns:
    <?php print_r($login_date); ?>
     
    • Thanks Thanks x 1
  11. littlewebdragon

    littlewebdragon Jr. VIP Jr. VIP

    Joined:
    Dec 30, 2007
    Messages:
    1,671
    Likes Received:
    826
    Occupation:
    Occupation
    Location:
    Location
    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?
     
    • Thanks Thanks x 1
  12. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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 ()."
     
  13. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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?
     
  14. teysuro

    teysuro Registered Member

    Joined:
    Sep 19, 2012
    Messages:
    62
    Likes Received:
    16
    Gender:
    Male
    Location:
    Netherlands
    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).
     
    • Thanks Thanks x 1
  15. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    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 :)
     
  16. teysuro

    teysuro Registered Member

    Joined:
    Sep 19, 2012
    Messages:
    62
    Likes Received:
    16
    Gender:
    Male
    Location:
    Netherlands
    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 Thanks x 1
  17. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,026
    Likes Received:
    218
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    Thanks man. I'm good about this. Much appreciated :)
     
    • Thanks Thanks x 1
  18. Tosmekop

    Tosmekop Supreme Member

    Joined:
    Oct 24, 2011
    Messages:
    1,314
    Likes Received:
    883
    "Hey, let's go check out the internet!"
    [​IMG]
     
    • Thanks Thanks x 1