http_cookie_set and http_cookie_remove#2643
http_cookie_set and http_cookie_remove#2643blar wants to merge 3 commits intophp:masterfrom blar:http_cookie
Conversation
|
I personally would prefer if the naming convention was the same as the already existing one to ensure we don't conflict with pecl/http, e.g.: removecookie() then alter setcookie() to check if the 3rd parameter is an array and handle from there, tho I do agree that removecookie() is a bad name. Lets see what the other core devs have of thoughts on this |
|
I know this PR is a tad old but couldn't the encoding be specified as a new key in the $options parameter (as of PHP 7.3) for the setcookie (and other related function such as session_set_cookie_params)? |
|
@Girgias already mentioned that we could add an PS: ah, overlooked |
|
I'm going to draw a line under this, there didn't seem to be the interest from the OP to keep going. |
bool http_cookie_set(string $name, string $value [, array $options])
expires: int, default: 0
path: string, default: ""
domain: string, default: ""
secure: bool, default: false
httponly: bool, default: false
encode: int, default: HTTP_COOKIE_ENCODE_RFC1738
Contants for encode option:
HTTP_COOKIE_ENCODE_NONE (same as setrawcookie)
HTTP_COOKIE_ENCODE_RFC1738 (same encoding as setcookie)
HTTP_COOKIE_ENCODE_RFC3986
If encoding is HTTP_COOKIE_ENCODE_NONE, then no encoding is performed. The caller is responsible for a correct encoding.
If encoding is HTTP_COOKIE_ENCODE_RFC1738, then encoding is performed per RFC 1738 and the application/x-www-form-urlencoded media type, which implies that spaces are encoded as plus (+) signs.
If encoding is HTTP_COOKIE_ENCODE_RFC3986, then encoding is performed according to RFC 3986, and spaces will be percent encoded (%20).
Set cookie with httponly without unnecessary pass the default values for $path, $domain or $secure like setcoookie() or setrawcookie()
Disable encoding and encode the value with another function:
bool http_cookie_remove(string $name);
Remove a cookie. No more need to look into the manual if the correct value is "", NULL or 0 to remove cookies.