Jump to content

Guides

ips.utils.cookie

Description

This utility provides methods for working with cookies in IPS4. It deals with cookie prefixes and other setting behind the scenes so that you can interact with cookies without having to handle those aspects manually.

 

Example

ips.utils.cookie.set( 'myKey', 'Hello world', true ); // Sets a sticky cookie
ips.utils.cookie.get( 'myKey' );
// -> Hello world
ips.utils.cookie.unset( 'myKey' );
ips.utils.cookie.get( 'myKey' );
// -> undefined

 

Methods

void set( string key, string value, mixed sticky )

Sets a new cookie, or overwrites an existing cookie with the same key.

  • key
    The key to store this value under, used for later retrieval.
  • value
    The value of this cookie.
  • sticky
    The cookie's expiration. If true, the cookie is set to be (effectively) permanent. If -1, the cookie will expire when the page reloads. Alternatively, an explict expiration date can be set by using the correct format, e.g. Mon, 16-Dec-2013 18:00:00 GMT

 

string get( string key )

Retrieves a previously set cookie. If the cookie doesn't exist, undefined is returned.

  • key
    The key to fetch.

 

void unset( string key )

Removes a previously set cookie.

  • key
    The cookie key to remove

  Report Guide


×