| | |
howto: expire cookie at end of session?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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?
[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?
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.
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:
PHP Syntax (Toggle Plain Text)
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 ::
Lafinboy Productions
:: Website Design :: Website Development ::
•
•
•
•
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:
PHP Syntax (Toggle Plain Text)
setcookie("TestCookie", $value,'','/','domain.com');
PHP Syntax (Toggle Plain Text)
setcookie($cookieName, $cookieValue, NULL, $path, $domain);
--Mark
Free tutorial books for beginners on PHP, JSP, ASP, SQL, XML, ...
--> http://www.herongyang.com/
--> http://www.herongyang.com/
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 ::
Lafinboy Productions
:: Website Design :: Website Development ::
![]() |
Similar Threads
- IE6/IE7 unexpectedly drops the PHP Session ID cookie (PHPSESSID) (PHP)
- Making links 'visited' from the server end (IT Professionals' Lounge)
- How to end a session immediately when the browser closes? (ASP.NET)
- How to end a session immediately when the browser closes? (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: Installation of PHP on Windows
- Next Thread: Variable scope/declaration/assignment query
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend





