Results 1 to 9 of 9

Thread: PHP Question

  1. #1

    PHP Question

    Hi,

    I have a fairly simple PHP question that's baffling me. I use time() to set a session variable so I can lock someone out after too many bad login attempts, but I'm getting a really strange result with my code ->

    Code:
    $_SESSION["loginlocked"] = time();
    echo time() - $_SESSION["loginlocked"];
    I keep getting numbers like -1182493278

    If I echo them seperately I get correct integers e.g ->

    1182493410 | 1182493278 which add up to to the correct number of seconds since the session was set.

    Any idea why I'm getting the massive negative number when I do the subtraction???

    Cheers,
    Niggles

  2. #2
    Hmm, forget my question. As soon as I put brackets around the equation it worked ->

    Code:
    echo (time() - $_SESSION["loginlocked"]);
    *boggle*

  3. #3
    Senior Member
    Join Date
    Oct 2003
    Location
    MA
    Posts
    1,052
    thats because when you do not enclose the whole line with () you are actually telling it to echo 2 separate things

  4. #4
    thats because when you do not enclose the whole line with () you are actually telling it to echo 2 separate things
    Originally, I had it as -

    Code:
    if(time() - $_SESSION["loginlocked"] > 600){
        doSomething();
    }
    which wasn't working - it was giving the negative 11 million number, so I echoed the equation to see what it was doing.

    So I'm still not sure why it didn't work - except that by enclosing it the subtraction in brackets it decided to work properly.

    Cheers,
    Niggles

  5. #5
    Senior Member
    Join Date
    Oct 2003
    Location
    MA
    Posts
    1,052
    if(time() - $_SESSION["loginlocked"] > 600){
    doSomething();
    }

    I think that would work...

  6. #6
    Senior Member Aardpsymon's Avatar
    Join Date
    Feb 2007
    Location
    St Annes (aaaa!)
    Posts
    434
    isn't that what he has already?

    try
    Code:
    if( (time() - $_SESSION["loginlocked"]) > 600){
        doSomething();
    }
    Last edited by Aardpsymon; June 26th, 2007 at 02:01 PM. Reason: formatting change
    If the world doesn't stop annoying me I will name my kids ";DROP DATABASE;" and get revenge.

  7. #7
    Senior Member
    Join Date
    Oct 2003
    Location
    MA
    Posts
    1,052
    Nope he didnt close the parentheses right before the > symbol

  8. #8
    Hi,

    It's all sorted - the () around the expression did the trick.

    Cheers and thanks,
    Niggles

  9. #9

Similar Threads

  1. Secure PHP Programming for PHP beginners.
    By chsh in forum The Security Tutorials Forum
    Replies: 18
    Last Post: April 1st, 2006, 02:13 PM
  2. Read Me First
    By Negative in forum The Security Tutorials Forum
    Replies: 12
    Last Post: June 2nd, 2004, 01:09 AM
  3. basic php with a database
    By johnnymier in forum Other Tutorials Forum
    Replies: 0
    Last Post: June 7th, 2003, 12:56 AM
  4. Test Your General Linux Knowledge
    By smirc in forum AntiOnline's General Chit Chat
    Replies: 6
    Last Post: May 13th, 2002, 04:35 PM
  5. Test Your Knowledge of Redhat?
    By smirc in forum AntiOnline's General Chit Chat
    Replies: 3
    Last Post: May 13th, 2002, 03:24 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
  •