cookie_helper.php
This file is part of 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
Functions
- set_cookie() : void
- Set cookie
- get_cookie() : array<string|int, mixed>|string|null
- 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
set_cookie(array<string|int, mixed>|Cookie|string $name[, string $value = '' ][, int $expire = 0 ][, string $domain = '' ][, string $path = '/' ][, string $prefix = '' ][, bool|null $secure = null ][, bool|null $httpOnly = null ][, string|null $sameSite = null ]) : void
Accepts seven parameters, or you can submit an associative array in the first parameter containing all the values.
Parameters
- $name : array<string|int, mixed>|Cookie|string
-
Cookie name / array containing binds / Cookie object
- $value : string = ''
-
The value of the cookie
- $expire : int = 0
-
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 ('': the default prefix)
- $secure : bool|null = null
-
True makes the cookie secure
- $httpOnly : bool|null = null
-
True makes the cookie accessible via http(s) only (no javascript)
- $sameSite : string|null = null
-
The cookie SameSite value
Tags
get_cookie()
Fetch an item from the $_COOKIE array
get_cookie(string $index[, bool $xssClean = false ][, string|null $prefix = '' ]) : array<string|int, mixed>|string|null
Parameters
- $index : string
- $xssClean : bool = false
- $prefix : string|null = ''
-
Cookie name prefix. '': the prefix in Config\Cookie null: no prefix
Tags
Return values
array<string|int, mixed>|string|nulldelete_cookie()
Delete a cookie
delete_cookie(string $name[, string $domain = '' ][, string $path = '/' ][, string $prefix = '' ]) : void
Parameters
- $name : string
- $domain : string = ''
-
the cookie domain. Usually: .yourdomain.com
- $path : string = '/'
-
the cookie path
- $prefix : string = ''
-
the cookie prefix
Tags
has_cookie()
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 = ''