Cookie / HttpCookieHandler
im\http\HttpCookieHandler
An implementation of the im\http\CookieHandler
interface
class HttpCookieHandler implements im\http\CookieHandler {
// Inherited Constants
public int F_LAX = 0x01
public int F_STRICT = 0x03
public int F_SECURE = 0x08
public int F_NOSCRIPT = 0x10
// Methods
public __construct(null|string $prefix = NULL, null|string $path = NULL, null|string $domain = NULL)
public writeToResponse(im\http\msg\ResponseBuilder $response): void
public readFromRequest(im\http\msg\Request $request): void
public set(string $name, string $value, int $expires = 0, null|string $path = NULL, int $flags = 0): void
public get(string $name): null|string
public remove(string $name): void
public has(string $name): bool
}
Name | Description |
---|---|
HttpCookieHandler :: F_LAX | Set SameSite to Lax mode |
HttpCookieHandler :: F_STRICT | Set SameSite to Strict mode |
HttpCookieHandler :: F_SECURE | Set the Secure flag on this cookie |
HttpCookieHandler :: F_NOSCRIPT | Set the HttpOnly flag on this cookie |
Name | Description |
---|---|
HttpCookieHandler :: __construct | |
HttpCookieHandler :: writeToResponse | Write all cookies to the headers of a response object |
HttpCookieHandler :: readFromRequest | Extract cookies from the headers of a request object |
HttpCookieHandler :: set | Add a new cookie |
HttpCookieHandler :: get | Get the value of a cookie |
HttpCookieHandler :: remove | Delete a cookie set by this handle |
HttpCookieHandler :: has | Check if a cookie exists |
$request = new ServerRequestBuilder();
$handler = new CookieHandler();
// Extract cookies from the request
$handler->readFromRequest($request);
// Set a new cookie
$handler->set("some_name", "Some Value", 3600 * 24, null, CookieHandler::F_SECURE);
// Remove a cookie
$handler->remove("another_name");
// Write this information into the response headers
$response = new HttpResponseBuilder();
$handler->writeToResponse($response);