|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-12-31 04:25 UTC] jason191 at herkamire dot com
Description: ------------ The documentation for setcookie() here: http://us2.php.net/manual/en/function.setcookie.php does not specify what value to pass to the "expire" parameter to get a session cookie. It does say that the default value is a session cookie, but doesn't say how to get this result by passing a value. This is important information for two reasons: 1) I wrote a function that calls setcookie() and has a parameter for the length of time the cookie will last. I would like to be able to inform users what value they can pass to get a session cookie. 2) Perhaps there is a way, but I don't know how to pass the parameters after "expire" without setting the "expire parameter. I'm sure many others don't know how either. One of the user comments says that he was able to get a session cookie by passing 0 (zero), but I do not know if this works across different PHP versions. Thank you for your time. Best regards, - Jason Woofenden PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 19:00:01 2025 UTC |
I'd put this in the description: The Unix timestamp for when the cookie should expire or 0 for a session cookie. (Session cookies should be kept until the browser closes.) Default is 0. See also: time(), mktime() And kill the second sentence in the example (since it's not an example.) Also, I think it is unreasonable to assume that people would assume that "not set"ing something would be the same as passing zero. For example, the following two calls produce dramatically different results: setcookie('foo', 'bar', $tomorrow); setcookie('foo', 'bar', $tomorrow, 0, 0); And I know I'm not alone it this. Buried in the comments on the docs page (link in my original post above) is someone asking what to pass in this parameter for a session cookie, and posting that it seemed to work by passing zero. Another post down lower passes false, which apparently also works. But neither of them have any idea if their solution works across different versions of PHP, or if it will continue to be supported.