Logo
  • Welcome to LavaLust
    • What is LavaLust?
    • MIT License
    • LavaLust Changelog
  • Installation Instructions
    • Installation Guide
    • Upgrading Version
  • LavaLust Overview
    • Getting Started
    • LavaLust at a Glance
    • Support Features
    • Features
    • Application Flow
    • Model–View–Controller
  • General Topics
    • Routes
    • Controllers
    • Models
    • Views
    • Helpers
    • Libraries
    • Auto-loading Resources
    • Common Functions and Error Handling
    • before_action Hook
    • Middleware
  • Database Reference
    • Database Reference
    • SQL Query Builder
  • Libraries
    • API Library
    • Cache Class
    • Config Class
    • Email Class
    • Encryption Class
    • Upload Class
    • Form Validation Class
    • Input and Output Class
    • Request
    • Response
    • Language Class
    • Migration Class
    • Pagination Class
    • Security Class
    • Session Class
    • Session Security
    • Performance Class
    • Ember Template Engine
    • Ember Registrar
  • Helpers
    • Cookie Helper
    • Directory Helper
    • Download Helper
    • File Helper
    • Language Helper
    • Security Helper
    • String Helper
    • URL & Asset Helper
  • CLI Tool
    • Available Commands
    • Development Server
    • Generating Files
    • Subdirectory Support
    • File Overwrite Protection
    • Getting Help
    • Tips and Best Practices
  • Examples
    • Blog CRUD using ORM
    • Blog CRUD using Query Builder
    • Pagination
    • User Authentication & Authorization
    • API Usage Sample
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.