Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 446 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

SetCookie:: (26 methods):
  fromString()
  __construct()
  __toString()
  toArray()
  getName()
  setName()
  getValue()
  setValue()
  getDomain()
  setDomain()
  getPath()
  setPath()
  getMaxAge()
  setMaxAge()
  getExpires()
  setExpires()
  getSecure()
  setSecure()
  getDiscard()
  setDiscard()
  getHttpOnly()
  setHttpOnly()
  matchesPath()
  matchesDomain()
  isExpired()
  validate()


Class: SetCookie  - X-Ref

Set-Cookie object

fromString(string $cookie)   X-Ref
Create a new SetCookie object from a string.

param: string $cookie Set-Cookie header string

__construct(array $data = [])   X-Ref

param: array $data Array of cookie data provided by a Cookie parser

__toString()   X-Ref
No description

toArray()   X-Ref
No description

getName()   X-Ref
Get the cookie name.

return: string

setName($name)   X-Ref
Set the cookie name.

param: string $name Cookie name

getValue()   X-Ref
Get the cookie value.

return: string|null

setValue($value)   X-Ref
Set the cookie value.

param: string $value Cookie value

getDomain()   X-Ref
Get the domain.

return: string|null

setDomain($domain)   X-Ref
Set the domain of the cookie.

param: string|null $domain

getPath()   X-Ref
Get the path.

return: string

setPath($path)   X-Ref
Set the path of the cookie.

param: string $path Path of the cookie

getMaxAge()   X-Ref
Maximum lifetime of the cookie in seconds.

return: int|null

setMaxAge($maxAge)   X-Ref
Set the max-age of the cookie.

param: int|null $maxAge Max age of the cookie in seconds

getExpires()   X-Ref
The UNIX timestamp when the cookie Expires.

return: string|int|null

setExpires($timestamp)   X-Ref
Set the unix timestamp for which the cookie will expire.

param: int|string|null $timestamp Unix timestamp or any English textual datetime description.

getSecure()   X-Ref
Get whether or not this is a secure cookie.

return: bool

setSecure($secure)   X-Ref
Set whether or not the cookie is secure.

param: bool $secure Set to true or false if secure

getDiscard()   X-Ref
Get whether or not this is a session cookie.

return: bool|null

setDiscard($discard)   X-Ref
Set whether or not this is a session cookie.

param: bool $discard Set to true or false if this is a session cookie

getHttpOnly()   X-Ref
Get whether or not this is an HTTP only cookie.

return: bool

setHttpOnly($httpOnly)   X-Ref
Set whether or not this is an HTTP only cookie.

param: bool $httpOnly Set to true or false if this is HTTP only

matchesPath(string $requestPath)   X-Ref
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

matchesDomain(string $domain)   X-Ref
Check if the cookie matches a domain value.

param: string $domain Domain to check against

isExpired()   X-Ref
Check if the cookie is expired.


validate()   X-Ref
Check if the cookie is valid according to RFC 6265.

return: bool|string Returns true if valid or an error message if invalid