Skip to content
Youmy001 edited this page Feb 4, 2018 · 3 revisions

The Cookie utility allows to easily read and write browser cookies. The class for the utility is named Cookie and part of the Core module.

This utility is only useful when the client sending the request supports client-side cookies. It is not advisable to rely on cookie on API calls.

Usage

To access the configuration utility, you must import the Cookie class from the Core module.

use Apine\Core\Cookie;

The class only contains static methods. It is not necessary to instanciate the class. You can directly call its methods.

To read a cookie, use the get method.

$value = Cookie::get('cookie_name');

To write a value to a cookie, use the set method.

Cookie::set('cookie_name', $value);

Methods

static get(string $cookie_name) : string

Read the value of a cookie.

Its only parameter is the name of the cookie to read. The method returns the value of the cookie if the cookie exists. It returns nothing if it cannot locate the cookie.

static set(string $cookie_name, string $cookie_value [, integer $expiration_time = 0]) : boolean

Write a value to a cookie.

This method has two mandatory parameters which are the name and the value of the cookie. The optional parameter is the expiration date of the cookie expressed as an UNIX timestamp. If set to 0, or omitted, the cookie will expire at the end of the session. The method returns TRUE if it was able to write the cookie or FALSE if an error occurs.

Clone this wiki locally