-
June 22nd, 2007, 07:31 AM
#1
Member
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
-
June 22nd, 2007, 07:35 AM
#2
Member
Hmm, forget my question. As soon as I put brackets around the equation it worked ->
Code:
echo (time() - $_SESSION["loginlocked"]);
*boggle*
-
June 25th, 2007, 02:50 PM
#3
thats because when you do not enclose the whole line with () you are actually telling it to echo 2 separate things
-
June 25th, 2007, 11:18 PM
#4
Member
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
-
June 26th, 2007, 01:38 PM
#5
if(time() - $_SESSION["loginlocked"] > 600){
doSomething();
}
I think that would work...
-
June 26th, 2007, 02:00 PM
#6
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.
-
June 26th, 2007, 04:03 PM
#7
Nope he didnt close the parentheses right before the > symbol
-
June 26th, 2007, 11:19 PM
#8
Member
Hi,
It's all sorted - the () around the expression did the trick.
Cheers and thanks,
Niggles
-
June 27th, 2007, 12:00 PM
#9
Similar Threads
-
By chsh in forum The Security Tutorials Forum
Replies: 18
Last Post: April 1st, 2006, 02:13 PM
-
By Negative in forum The Security Tutorials Forum
Replies: 12
Last Post: June 2nd, 2004, 01:09 AM
-
By johnnymier in forum Other Tutorials Forum
Replies: 0
Last Post: June 7th, 2003, 12:56 AM
-
By smirc in forum AntiOnline's General Chit Chat
Replies: 6
Last Post: May 13th, 2002, 04:35 PM
-
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
-
Forum Rules
|
|