howto: expire cookie at end of session?

Reply

Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

howto: expire cookie at end of session?

 
0
  #1
Nov 22nd, 2005
so I'm looking at the PHP docs for setcookie and this is what I see:
[PHP]bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )[/PHP]
they say if you want to have the cookie expire when the browser closes then do something like this:
setcookie("TestCookie", $value);

But I want this cookie to work on several subdomains no I need to fill in the domain part... is there any way around this in PHP?
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: howto: expire cookie at end of session?

 
0
  #2
Nov 22nd, 2005
If you do not require the cookie to set on a computer/browser for certain length of time (few hours to few months), you can simply use session. Session is a safer option as some browsers block cookies. By the end of a session, use unset to remove the session value. Sessio will end automatically when the browser closed.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 166
Reputation: Lafinboy is an unknown quantity at this point 
Solved Threads: 7
Lafinboy's Avatar
Lafinboy Lafinboy is offline Offline
Junior Poster

Re: howto: expire cookie at end of session?

 
0
  #3
Nov 23rd, 2005
The values in [ ] in the function are optional, but if you want to skip one you need to put a placeholder value in, along the lines of:
  1. setcookie("TestCookie", $value,'','/','domain.com');
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.

Lafinboy Productions
:: Website Design :: Website Development ::

Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 12
Reputation: mark1048 is an unknown quantity at this point 
Solved Threads: 0
mark1048's Avatar
mark1048 mark1048 is offline Offline
Newbie Poster

Re: howto: expire cookie at end of session?

 
0
  #4
Dec 3rd, 2005
Originally Posted by Lafinboy
The values in [ ] in the function are optional, but if you want to skip one you need to put a placeholder value in, along the lines of:
  1. setcookie("TestCookie", $value,'','/','domain.com');
The above code will not work. Try this:
  1. setcookie($cookieName, $cookieValue, NULL, $path, $domain);
You can read more tutorials on Cookies at: http://www.herongyang.com/php/cookie.html

--Mark
Free tutorial books for beginners on PHP, JSP, ASP, SQL, XML, ...
--> http://www.herongyang.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 166
Reputation: Lafinboy is an unknown quantity at this point 
Solved Threads: 7
Lafinboy's Avatar
Lafinboy Lafinboy is offline Offline
Junior Poster

Re: howto: expire cookie at end of session?

 
0
  #5
Dec 4th, 2005
Exactly right, sorry, my bad. The expires value is the only non-string value, and so must be set to either null or 0 (zero), which will expire the cookie when the session ends.
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.

Lafinboy Productions
:: Website Design :: Website Development ::

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC