The defaults or previously set options from an options() method call are used for any $options not specified.
Available since version 3.0.141.
Example
$input->cookie->foo = 'bar'; // set with default options (expires with session)
$input->cookie->set('foo', 'bar'); // same as above
$input->cookie->set('foo', bar', 86400); // expire after 86400 seconds (1 day)
$input->cookie->set('foo', 'bar', [ // set with options
'age' => 86400,
'path' => $page->url,
'httponly' => true,
]);
Usage
// basic usage$wireInputDataCookie->set(string $key, string $value);
// usage with all arguments$wireInputDataCookie->set(string $key, string $value, $options= []);
Arguments
Name
Type(s)
Description
key
string
Cookie name
value
string
Cookie value
options (optional)
array, int, string
Specify int for age option, string for expire option, or array for multiple options:
age(int): Max age of cookies in seconds or 0 to expire with session. For example: 3600=1 hour, 86400=1 day,
604800=1 week, 2592000=30 days, etc. (default=0, expire with session)
expire(int|string): If you prefer to use an expiration date rather than the age option, specify a unix timestamp (int),
ISO-8601 date string, or any date string recognized by PHP’s strtotime(), like "2020-11-03" or +1 WEEK", etc. (default=null).
Please note the expire option was added in 3.0.159, previous versions should use the age option only.
path(string|null): Cookie path/URL or null for PW installation’s root URL. (default=null)
secure(bool|null): Transmit cookies only over secure HTTPS connection? Specify true or false, or use null to auto-detect,
which uses true for cookies set when HTTPS is detected. (default=null)
httponly(bool): When true, cookie is visible to PHP/ProcessWire only and not visible to client-side JS code. (default=false)
fallback(bool): If set cookie fails (perhaps due to output already sent), attempt to set at beginning of next request? (default=true)
domain(string|bool|null): Cookie domain, specify one of the following: null or blank string for current hostname [default],
boolean true for all subdomains of current domain, domain.com for domain.com and *.domain.com [same as true], www.domain.com
for www subdomain and and hostnames off of it, like dev.www.domain.com. (default=null, current hostname)
Return value
$this
Object instance it was called from (method supports fluent interface).
ProcessWire Weekly #560 In the 560th issue of ProcessWire Weekly we'll check out the latest core updates, cover newly released ProcessWire modules, and more. Read on!
Weekly.pw / 1 February 2025
ProcessWire 3.0.244 new main/master version ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
Blog / 18 January 2025
Subscribe to weekly ProcessWire news
“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani