Log in

View Full Version : mysql timestamp in php



mutago
04-23-2014, 02:55 PM
I want to lock users login account every 2 days
i created login_time as timestamp.

The problem is that 2 days has passed but i can still login with the account whereas
the account is suppossed to be lock for every 2 days. its seems there is a problem with the fetch query

Any help

Thank You.




<?php

//PDO Connection

$statement = $db->prepare('
SELECT id,login_time,username FROM membersuyg58ftplkbv
WHERE username = :username');

$statement->execute(array(
':username' => $txtusername);


// catch id by fetching its database row and lock the account for every 2 days

$catch = $statement->fetch();
if (($catch[0]) > (2 * 24 * 60 * 60)) {

echo 'account lock';
}else{
echo 'login ok';
}
?>

traq
04-24-2014, 01:52 AM
$catch[0] is going to be the id value.

Looks like you're using PDO? fetch (http://php.net/pdostatement.fetch) defaults to fetching both column names and numbered indexes. It would be most reliable to use $catch["login_time"].

I assume login_time is a unix timestamp. You need to compare this timestamp to (2*24*60*60) plus the current time (otherwise, you're comparing every login_time to midnight, January 3, 1970).

Related question: are you not actually checking the password when you log in?