setrawcookie()


Overview

setrawcookie() is a PHP function used to send a cookie without encoding its value in the url. Versions: PHP 5, PHP 7, PHP 8.

Note:
Use setcookie() if you'd like to automatically urlencode the cookie's value.

Parameters

setrawcookie() can have seven parameters:

name: the name of the cookie.
value: the value of the cookie.
expires_or_options: in seconds, the expiration time of the cookie. If set to 0, the cookie will die at the end of the session (when the browser is closed).
path: scope of the cookie: if set to /, the cookie will be available on the entire site. If set to /exemple/, the cookie will only be set to the /exemple/ directory.<
domain: domain or subdomain where the cookie will be active. if set to raided.eu, the cookie will be active on the entire raided.eu domain. If set to liblex.raided.eu, the cookie will only be active on the liblex.raided.eu subdomain.
secure: sets if the cookie should only be transmitted over HTTPS. If set to true, the cookie will only be transitted over HTTPS (safer).
httponly: sets if the cookie should only be transmitted over HTTP/HTTPS. If set to true, the cookie will only be transitted over HTTP/HTTPS. If set to false, the cookie will be transmitted over any protocol.
options: associative array, used to set the following option keys: expires, path, domain, secure, httponly & samesite. samesite may only be set to the following values: None, Lax or Strict. Without a samesite mention, no samesite attribute will be set.

Return possibilities

setrawcookie() will return true if the operation has successfully completed, false if it has failed.

Example

php
setrawcookie(
'cookie_name',
'cookie_value',
'100',
'/',
'raided.eu',
true,
true
);

See also

setcookie()
document.cookie
RFC 6265 (IETF)