Page 1 of 1
Where and when do I delete my cookie on the page?
Posted: Fri May 28, 2004 8:49 am
by ljCharlie
I have my cookie set as setcookie("UserName", $userName, time()+3600); on the very top of the page. Now, where and when do I delete my cookie on the page?
Any help is grateful!
ljCharlie
Posted: Fri May 28, 2004 9:46 am
by pickle
In my experience, you can't delete the cookie, just change it's value. A second call to setCookie does it fine.
Posted: Fri May 28, 2004 9:55 am
by Grim...
You can delete a cookie by setting its time in the past
Code: Select all
setcookie("UserName", $userName, time()-3600);
or by giving a blank value
Code: Select all
setcookie("UserName", '', time()+3600);
Posted: Fri May 28, 2004 10:34 am
by Joe
Yeah Grims method is best, however you can use javascript from what I know but it is not as reliable.
Posted: Fri May 28, 2004 11:05 am
by Grim...
Yes, best method is a combination of the two:
Code: Select all
setcookie("UserName", '', time()-3600);
Of course, bear in mind that your cookie expires (deletes itself) one hour after it was set anyway.
A cookie set without a time deletes itself as soon as the user browses away from your site or closes their browser.
Code: Select all
setcookie("UserName", '$username');
Posted: Fri May 28, 2004 11:52 am
by ljCharlie
Ah! So if I already have my cookie set to expire after one hour then I don't have to menually set the time in reverse to delete the cookie, correct?
ljCharlie
Posted: Fri May 28, 2004 11:57 am
by code_monkey
why not just use session variables?
Posted: Fri May 28, 2004 2:11 pm
by ljCharlie
What is session variables and how do I implement it?
ljCharlie
Posted: Fri May 28, 2004 2:43 pm
by Weirdan
Grim... wrote:
A cookie set without a time deletes itself as soon as the user browses away from your site or closes their browser.
Session cookie (cookie without a time set) gets deleted
only when you close your browser. phpBB, for example, does use session cookie. Grim, you could navigate away from this forums, then return back and be still logged in.
Posted: Fri May 28, 2004 8:48 pm
by maqmus