Cookie

Provides an interace for manipulating HTTP cookies.

Create a cookie object and access its value with the value property. Use \HotMelt\Cookie::update() to change its value and send the cookie back to the client, or use \HotMelt\Cookie::delete() to delete the cookie.

property-read

The value of the cookie. Use \HotMelt/Cookie::update() to change.

Methods

Initialize a cookie object.

__construct(string $name, string $path = '/', string $domain = null) 

Arguments

$name

string

The name of the cookie.

$path

string

The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the \/foo/ directory and all sub-directories such as \/foo/bar/ of $domain. The default value is the current directory that the cookie is being set in.

$domain

string

The domain that the cookie is available to. Setting the domain to 'www.example.com' will make the cookie available in the www subdomain and higher subdomains. Cookies available to a lower domain, such as 'example.com' will be available to higher subdomains, such as 'www.example.com'. Older browsers still implementing the deprecated RFC 2109 may require a leading . to match all subdomains.

Update the value of a cookie object.

update(mixed $value, int $time) : void

Arguments

$value

mixed

The value to set.

$time

int

The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).

Delete a cookie (make it expire immediately).

delete() : void

Properties

value

value : mixed

The value of the cookie. Use \HotMelt/Cookie::update() to change.

Type(s)

mixed