Copied!

Set-Cookie object

CloneableInstantiable
Methods
public __construct(array $data = [])
 
  • param array $data Array of cookie data provided by a Cookie parser
public __toString() : string
public static fromString(string $cookie) : self
 

Create a new SetCookie object from a string.

  • param string $cookie Set-Cookie header string
public getDiscard()
 

Get whether or not this is a session cookie.

  • return bool|null
public getDomain()
 

Get the domain.

  • return string|null
public getExpires()
 

The UNIX timestamp when the cookie Expires.

  • return string|int|null
public getHttpOnly()
 

Get whether or not this is an HTTP only cookie.

  • return bool
public getMaxAge()
 

Maximum lifetime of the cookie in seconds.

  • return int|null
public getName()
 

Get the cookie name.

  • return string
public getPath()
 

Get the path.

  • return string
public getSecure()
 

Get whether or not this is a secure cookie.

  • return bool
public getValue()
 

Get the cookie value.

  • return string|null
public isExpired() : bool
 

Check if the cookie is expired.

public matchesDomain(string $domain) : bool
 

Check if the cookie matches a domain value.

  • param string $domain Domain to check against
public matchesPath(string $requestPath) : bool
 

Check if the cookie matches a path value.

A request-path path-matches a given cookie-path if at least one of the following conditions holds:

  • The cookie-path and the request-path are identical.
  • The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
  • The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.
  • param string $requestPath Path to check against
public setDiscard( $discard) : void
 

Set whether or not this is a session cookie.

  • param bool $discard Set to true or false if this is a session cookie
public setDomain( $domain) : void
 

Set the domain of the cookie.

  • param string|null $domain
public setExpires( $timestamp) : void
 

Set the unix timestamp for which the cookie will expire.

  • param int|string|null $timestamp Unix timestamp or any English textual datetime description.
public setHttpOnly( $httpOnly) : void
 

Set whether or not this is an HTTP only cookie.

  • param bool $httpOnly Set to true or false if this is HTTP only
public setMaxAge( $maxAge) : void
 

Set the max-age of the cookie.

  • param int|null $maxAge Max age of the cookie in seconds
public setName( $name) : void
 

Set the cookie name.

  • param string $name Cookie name
public setPath( $path) : void
 

Set the path of the cookie.

  • param string $path Path of the cookie
public setSecure( $secure) : void
 

Set whether or not the cookie is secure.

  • param bool $secure Set to true or false if secure
public setValue( $value) : void
 

Set the cookie value.

  • param string $value Cookie value
public toArray() : array
public validate()
 

Check if the cookie is valid according to RFC 6265.

  • return bool|string Returns true if valid or an error message if invalid
Properties
private $data = NULL
 
  • var array Cookie data
private static $defaults = ['Name' => NULL, 'Value' => NULL, 'Domain' => NULL, 'Path' => '/', 'Max-Age' => NULL, 'Expires' => NULL, 'Secure' => false, 'Discard' => false, 'HttpOnly' => false]
 
  • var array
Properties
private static $defaults = ['Name' => NULL, 'Value' => NULL, 'Domain' => NULL, 'Path' => '/', 'Max-Age' => NULL, 'Expires' => NULL, 'Secure' => false, 'Discard' => false, 'HttpOnly' => false]
 
  • var array
Methods
public static fromString(string $cookie) : self
 

Create a new SetCookie object from a string.

  • param string $cookie Set-Cookie header string
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration