SPHPlayground API
SPHPlayground
sphplayground sphplayground

HTTP headers components

BASIC INFORMATION:

HTTP headers let the client and the server pass additional information with a message in a request or response. [1]

NOTE: Remember that Header::send() just like PHP's native header() must be called before any actual output is sent. It is a very common error to have spaces or empty lines that are output before headers are called. [2]

HTTP header

An HTTP cookie is a small block of data created by a web server while a user is browsing a website and placed on the user's device by the user's web browser. [3]

Cookies serve useful and sometimes essential functions on the web. They enable web servers to store stateful information on the user's device. [3]

Header types:

Synopsis
interface Header implements Stringable
Returns header name
public getName():string
Returns header value
public getValue():mixed
Saves the header information
public send():bool
Deletes the cookie
public remove():bool

HTTP cookie

An HTTP cookie is a small block of data created by a web server while a user is browsing a website and placed on the user's device by the user's web browser. [3]

Cookies serve useful and sometimes essential functions on the web. They enable web servers to store stateful information on the user's device. [3]

Cookie types:

Synopsis
class Cookie implements Header
Prepares a new cookie
public __construct(string $name, Stringable|string|int|float $value = '')
public __toString():string
Returns the name of the cookie
public getName():string
Returns the value of the cookie
public getValue():string
Sets the value for the cookie
public setValue(Stringable|string|int|float $value):static
Returns the expiry time of the cookie
public getExpiryTime():int
Sets the expiry time for the cookie
public setExpiryTime(int $expiryTime):static
Returns the maximum age of the cookie (i.e. the remaining lifetime)
public getMaxAge():int
Sets the expiry time for the cookie based on the specified maximum age (i.e. the remaining lifetime)
public setMaxAge(int $maxAge):static
Returns the path of the cookie
public getPath():string
Sets the path for the cookie
public setPath(?string $path = null):static
Returns the domain of the cookie
public getDomain():?string
Sets the domain for the cookie
public setDomain(?string $domain = null):static
Returns whether the cookie should be accessible through HTTP only
public isHttpOnly():bool
Sets whether the cookie should be accessible through HTTP only
public setHttpOnly(bool $httpOnly):static
Returns whether the cookie should be sent over HTTPS only
public isSecureOnly():bool
Sets whether the cookie should be sent over HTTPS only
public setSecureOnly(bool $secureOnly):static
Returns the same-site restriction of the cookie
public getSameSite():?SameSite
Sets the same-site restriction for the cookie
public setSameSiteRestriction(?SameSite $sameSite = null):static
public isDeleted():bool
Saves the header information
public send():bool
Deletes the cookie
public remove():bool
Checks whether a cookie with the specified name exists
public static exists(string $name):bool
Returns the value from the requested cookie
public static get(string $name):?string