Results 1 to 2 of 2

Thread: mysql timestamp in php

  1. #1
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Default mysql timestamp in php

    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.

    //PDO Connection
    $statement = $db->prepare('
    		SELECT id,login_time,username FROM membersuyg58ftplkbv
    		WHERE username = :username');
    ':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';
    echo 'login ok';

  2. #2
    Join Date
    Apr 2008
    Thanked 516 Times in 502 Posts
    Blog Entries


    $catch[0] is going to be the id value.

    Looks like you're using PDO? 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?

Similar Threads

  1. Replies: 3
    Last Post: 12-19-2013, 12:59 AM
  2. Automatic TimeStamp Actions
    By Techykid3 in forum MySQL and other databases
    Replies: 20
    Last Post: 09-01-2011, 08:33 PM
  3. how to display MySQL timestamp?
    By jr_yeo in forum MySQL and other databases
    Replies: 15
    Last Post: 02-01-2009, 07:33 PM
  4. MySQL Timestamp into PHP Format
    By cancer10 in forum PHP
    Replies: 1
    Last Post: 03-17-2008, 03:43 AM
  5. how to edit timestamp entries
    By blwow in forum PHP
    Replies: 5
    Last Post: 05-06-2007, 08:30 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts