LavaLust
  • Welcome to LavaLust
  • Installation Instructions
  • LavaLust Overview
  • General Topics
  • Database Reference
  • Libraries
  • Helpers
    • Cookie Helper
      • Function Summary
      • Available Functions
        • set_cookie()
        • get_cookie()
        • delete_cookie()
      • Additional Notes
    • Directory Helper
    • Download Helper
    • File Helper
    • Language Helper
    • Security Helper
    • String Helper
    • URL & Asset Helper
  • Examples
LavaLust
  • Helpers
  • Cookie Helper

Cookie Helper

The Cookie Helper provides a set of functions to simplify working with browser cookies in LavaLust. It allows you to set, retrieve, and delete cookies through a simple API.

Note

This helper uses the framework’s internal IO class through lava_instance()->io. Make sure the IO class is properly loaded by the framework (it is loaded automatically in normal operation).

Function Summary

Function

Description

set_cookie()

Sets a new cookie with optional parameters.

get_cookie()

Retrieves a cookie value from the browser.

delete_cookie()

Deletes an existing cookie from the browser.

Available Functions

set_cookie($name, $value = '', $expiration = 0, $options = array())

Sets a cookie in the user’s browser.

Parameters:
  • $name (string) – The cookie name.

  • $value (string) – The cookie value (default: empty string).

  • $expiration (int) – Cookie expiration time in seconds (default: 0, meaning “until the browser is closed”).

  • $options (array) – Optional array of additional cookie settings such as domain, path, secure, and httponly.

Returns:

void

Example:

<?php
set_cookie('username', 'ronald', 3600, [
    'path'     => '/',
    'secure'   => true,
    'httponly' => true
])
get_cookie($name)

Fetches an item from the $_COOKIE array.

Parameters:
  • $name (string) – The name of the cookie to retrieve.

Returns:

mixed — The cookie value if it exists, or null if it does not.

Example:

<?php
$username = get_cookie('username');
if ($username !== null) {
    echo "Welcome back, $username!";
}
delete_cookie($name, $domain = '', $path = '/', $prefix = '')

Deletes a cookie from the browser.

Parameters:
  • $name (string) – The name of the cookie to delete.

  • $domain (string) – The domain of the cookie (optional).

  • $path (string) – The path of the cookie (default: '/').

  • $prefix (string) – An optional cookie prefix.

Returns:

void

Example:

<?php
delete_cookie('username');

Additional Notes

  • If your app uses a cookie prefix (set via the cookie_prefix config item), get_cookie() will attempt to resolve it automatically.

  • The helper functions are simple wrappers around lava_instance()->io->set_cookie() and lava_instance()->io->cookie() for convenience.

Previous Next

© Copyright 2026, LavaLust PHP Framework.