stevencopley
asked on
cookie question
why wont the following expire after 5 seconds ... or do I misunderstand 'expire'. (I thought it should delete its self)
setcookie('bob','hello',ti me()+5);
setcookie('bob','hello',ti
I can't even write my own name :(
jpoesen
jpoesen
???
Are you going to award points?
Are you going to award points?
sure hope so :)
jpoesen, I don't think you are correct.
From the PHP manual ...
Some examples follow how to send cookies: Example 1. setcookie() send examples
setcookie ("TestCookie", $value);
setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */
setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1);
The setcookie parameters are ...
setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
The expire parameter requires a proper time (i.e. time()).
So, there is no reason that
setcookie('bob','hello',ti me()+5);
will not create a cookie that will expire in 5 seconds.
Steven,
Once you've set the cookie with an automatic timeout, what are you doing to determine that the cookie has NOT expired as expected?
Richard.
From the PHP manual ...
Some examples follow how to send cookies: Example 1. setcookie() send examples
setcookie ("TestCookie", $value);
setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */
setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1);
The setcookie parameters are ...
setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
The expire parameter requires a proper time (i.e. time()).
So, there is no reason that
setcookie('bob','hello',ti
will not create a cookie that will expire in 5 seconds.
Steven,
Once you've set the cookie with an automatic timeout, what are you doing to determine that the cookie has NOT expired as expected?
Richard.
Quite right. I used on old version of my message board to check. It was a version where I already started using session vars instead.
My mistake.
setcookie('bob','hello',ti me()+5);
makes a cookie that expires. But I don't think that "expires" means that the cookie is deleted, just that it is no longer valid.
Thanks for noticing, RQuadling.
jpoesen.
My mistake.
setcookie('bob','hello',ti
makes a cookie that expires. But I don't think that "expires" means that the cookie is deleted, just that it is no longer valid.
Thanks for noticing, RQuadling.
jpoesen.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I thought that if I tried to reference
I tried what jpoesen said but 'bob' , once it had timed out I'd get '' instead of 'hello'.
I tried what jpoesen said but its still there.
what I did was saved time() to bob and then when I checked it, I compared bob to time() to see how long since it had been accessed, since it doesn't seem to disappear.
Thanks everyone for your help.
I tried what jpoesen said but 'bob' , once it had timed out I'd get '' instead of 'hello'.
I tried what jpoesen said but its still there.
what I did was saved time() to bob and then when I checked it, I compared bob to time() to see how long since it had been accessed, since it doesn't seem to disappear.
Thanks everyone for your help.
ASKER
I meant.
I tried what jpoesen said but 'bob' , once it had timed out I thought I'd get '' instead of 'hello'.
I tried what jpoesen said but 'bob' , once it had timed out I thought I'd get '' instead of 'hello'.
As a result, if you use time()+5 you get the amount of seconds since 1970 (about 1 billion seconds) + 5 sec, so you set your cookie to expire in rougly 32 years.
php manual :
time()
- Return current UNIX timestamp
- usage:int time (void)
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
In short, use
setcookie('bob','hello',5)
Good luck
jpoesnen