Documentation

cookie_helper.php

This file is part of the CodeIgniter 4 framework.

(c) CodeIgniter Foundation admin@codeigniter.com

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Table of Contents

set_cookie()  : mixed
Set cookie
get_cookie()  : mixed
Fetch an item from the $_COOKIE array
delete_cookie()  : void
Delete a cookie
has_cookie()  : bool
Checks if a cookie exists by name.

Functions

Set cookie

set_cookie(string|array<string|int, mixed> $name[, string $value = '' ][, string $expire = '' ][, string $domain = '' ][, string $path = '/' ][, string $prefix = '' ][, bool $secure = false ][, bool $httpOnly = false ][, string|null $sameSite = null ]) : mixed

Accepts seven parameters, or you can submit an associative array in the first parameter containing all the values.

Parameters
$name : string|array<string|int, mixed>

Cookie name or array containing binds

$value : string = ''

The value of the cookie

$expire : string = ''

The number of seconds until expiration

$domain : string = ''

For site-wide cookie. Usually: .yourdomain.com

$path : string = '/'

The cookie path

$prefix : string = ''

The cookie prefix

$secure : bool = false

True makes the cookie secure

$httpOnly : bool = false

True makes the cookie accessible via http(s) only (no javascript)

$sameSite : string|null = null

The cookie SameSite value

Tags
see
Response::setCookie()
Return values
mixed

Fetch an item from the $_COOKIE array

get_cookie(string $index[, bool $xssClean = false ]) : mixed
Parameters
$index : string
$xssClean : bool = false
Tags
see
IncomingRequest::getCookie()
Return values
mixed

Delete a cookie

delete_cookie(mixed $name[, string $domain = '' ][, string $path = '/' ][, string $prefix = '' ]) : void
Parameters
$name : mixed
$domain : string = ''

the cookie domain. Usually: .yourdomain.com

$path : string = '/'

the cookie path

$prefix : string = ''

the cookie prefix

Tags
see
Response::deleteCookie()
Return values
void

Checks if a cookie exists by name.

has_cookie(string $name[, string|null $value = null ][, string $prefix = '' ]) : bool
Parameters
$name : string
$value : string|null = null
$prefix : string = ''
Return values
bool

Search results