note 69720 added to function.setcookie
| From: | abdullah dot a at gmail dot com | Date: | Sun, 17 Sep 2006 18:20:04 +0000 |
| Subject: | note 69720 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117268@lists.php.net to get a copy of this message | ||
Now, for a non-buggy setcookie that doesn't vanish on Location: redirects. In fact, I suggest
you use this instead of the built-in setcookie() function. It also supports "HttpOnly".
Usage is the same as the original setcookie() function:
<?php
function set_cookie($name, $value = '', $expires = 0, $path = '', $domain =
'', $secure = false, $http_only = false)
{
header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
. (empty($expires) ? '' : '; expires=' .
gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires))
. (empty($path) ? '' : '; path=' . $path)
. (empty($domain) ? '' : '; domain=' . $domain)
. (!$secure ? '' : '; secure')
. (!$http_only ? '' : '; HttpOnly'), false);
}
To make a "raw" version of this, get rid of the rawurlencode functions.
----
Server IP: 66.163.161.117
Probable Submitter: 75.126.9.18
----
Manual Page -- http://www.php.net/manual/en/function.setcookie.php
Edit -- https://master.php.net/note/edit/69720
Del: integrated -- https://master.php.net/note/delete/69720/integrated
Del: useless -- https://master.php.net/note/delete/69720/useless
Del: bad code -- https://master.php.net/note/delete/69720/bad+code
Del: spam -- https://master.php.net/note/delete/69720/spam
Del: non-english -- https://master.php.net/note/delete/69720/non-english
Del: in docs -- https://master.php.net/note/delete/69720/in+docs
Del: other reasons-- https://master.php.net/note/delete/69720
Reject -- https://master.php.net/note/reject/69720
Search -- https://master.php.net/manage/user-notes.php