Where and when do I delete my cookie on the page?
Moderator: General Moderators
Where and when do I delete my cookie on the page?
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
Any help is grateful!
ljCharlie
You can delete a cookie by setting its time in the past or by giving a blank value
Code: Select all
setcookie("UserName", $userName, time()-3600);Code: Select all
setcookie("UserName", '', time()+3600);Yes, best method is a combination of the two:
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", '', time()-3600);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');- code_monkey
- Forum Newbie
- Posts: 16
- Joined: Tue Jul 08, 2003 6:13 am
- Location: UK
- Contact:
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.Grim... wrote: A cookie set without a time deletes itself as soon as the user browses away from your site or closes their browser.