• Welcome to CodeIgniter4
    • Welcome to CodeIgniter4
    • Server Requirements
    • Credits
    • PSR Compliance
  • Installation
    • Downloading CodeIgniter
    • Installation
    • Upgrading From a Previous Version
    • Troubleshooting
    • Local Development Server
  • Tutorial
    • Static pages
    • News section
    • Create news items
    • Conclusion
  • CodeIgniter4 Overview
    • Application Structure
    • Models, Views, and Controllers
    • Autoloading Files
    • Services
    • Working With HTTP Requests
    • Security Guidelines
  • General Topics
    • Working With Configuration Files
    • CodeIgniter URLs
    • Controllers
    • Views
    • View Cells
    • View Renderer
    • View Parser
    • Helper Functions
    • Creating Core System Classes
    • Hooks - Extending the Framework Core
    • Global Functions and Constants
    • URI Routing
    • Controller Filters
    • Logging Information
    • Error Handling
    • Debugging Your Application
    • Web Page Caching
    • Running via the CLI
    • Custom CLI Commands
    • Code Modules
    • Managing your Applications
    • Handling Multiple Environments
    • Alternate PHP Syntax for View Files
    • Testing
  • Library Reference
    • API Response Trait
    • Benchmarking
    • Caching Driver
    • CLI Library
    • Content Negotiation
    • Localization
    • CURLRequest Class
    • IncomingRequest Class
    • HTTP Messages
    • Pagination
    • Request Class
    • HTTP Responses
    • Security Class
    • Session Library
    • Throttler
    • Typography
    • Working with Uploaded Files
    • Working with URIs
    • Validation
  • Database Reference
    • Quick Start: Usage Examples
    • Database Configuration
    • Connecting to a Database
    • Running Queries
    • Generating Query Results
    • Query Helper Functions
    • Query Builder Class
    • Transactions
    • Getting MetaData
    • Custom Function Calls
    • Using CodeIgniter’s Model
    • Database Manipulation with Database Forge
    • Database Migrations
    • Database Seeding
    • Database Hooks
  • Helpers
    • Cookie Helper
    • Filesystem Helper
    • Form Helper
    • HTML Helper
    • Inflector Helper
    • Number Helper
    • Text Helper
    • URL Helper
  • Contributing to CodeIgniter
    • Contribution Guidelines
    • Contribution Workflow
    • Contribution Signing
    • CodeIgniter4 Roadmap
    • CodeIgniter Internals Overview
    • Writing CodeIgniter Documentation
    • PHP Style Guide
    • Developer’s Certificate of Origin 1.1
Toggle Table of Contents
CodeIgniter4
  • Welcome to CodeIgniter4
    • Welcome to CodeIgniter4
    • Server Requirements
    • Credits
    • PSR Compliance
  • Installation
    • Downloading CodeIgniter
    • Installation
    • Upgrading From a Previous Version
    • Troubleshooting
    • Local Development Server
  • Tutorial
    • Static pages
    • News section
    • Create news items
    • Conclusion
  • CodeIgniter4 Overview
    • Application Structure
    • Models, Views, and Controllers
    • Autoloading Files
    • Services
    • Working With HTTP Requests
    • Security Guidelines
  • General Topics
    • Working With Configuration Files
    • CodeIgniter URLs
    • Controllers
    • Views
    • View Cells
    • View Renderer
    • View Parser
    • Helper Functions
    • Creating Core System Classes
    • Hooks - Extending the Framework Core
    • Global Functions and Constants
    • URI Routing
    • Controller Filters
    • Logging Information
    • Error Handling
    • Debugging Your Application
    • Web Page Caching
    • Running via the CLI
    • Custom CLI Commands
    • Code Modules
    • Managing your Applications
    • Handling Multiple Environments
    • Alternate PHP Syntax for View Files
    • Testing
  • Library Reference
    • API Response Trait
    • Benchmarking
    • Caching Driver
    • CLI Library
    • Content Negotiation
    • Localization
    • CURLRequest Class
    • IncomingRequest Class
    • HTTP Messages
    • Pagination
    • Request Class
    • HTTP Responses
    • Security Class
    • Session Library
    • Throttler
    • Typography
    • Working with Uploaded Files
    • Working with URIs
    • Validation
  • Database Reference
    • Quick Start: Usage Examples
    • Database Configuration
    • Connecting to a Database
    • Running Queries
    • Generating Query Results
    • Query Helper Functions
    • Query Builder Class
    • Transactions
    • Getting MetaData
    • Custom Function Calls
    • Using CodeIgniter’s Model
    • Database Manipulation with Database Forge
    • Database Migrations
    • Database Seeding
    • Database Hooks
  • Helpers
    • Cookie Helper
    • Filesystem Helper
    • Form Helper
    • HTML Helper
    • Inflector Helper
    • Number Helper
    • Text Helper
    • URL Helper
  • Contributing to CodeIgniter
    • Contribution Guidelines
    • Contribution Workflow
    • Contribution Signing
    • CodeIgniter4 Roadmap
    • CodeIgniter Internals Overview
    • Writing CodeIgniter Documentation
    • PHP Style Guide
    • Developer’s Certificate of Origin 1.1
 
CodeIgniter4
  • Docs »
  • Helpers »
  • Cookie Helper
  • classic layout

Cookie Helper¶

The Cookie Helper file contains functions that assist in working with cookies.

  • Loading this Helper
  • Available Functions

Loading this Helper¶

This helper is loaded using the following code:

helper('cookie');

Available Functions¶

The following functions are available:

set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = false[, $httpOnly = false]]]]]]])¶
Parameters:
  • $name (mixed) – Cookie name or associative array of all of the parameters available to this function
  • $value (string) – Cookie value
  • $expire (int) – Number of seconds until expiration
  • $domain (string) – Cookie domain (usually: .yourdomain.com)
  • $path (string) – Cookie path
  • $prefix (string) – Cookie name prefix
  • $secure (bool) – Whether to only send the cookie through HTTPS
  • $httpOnly (bool) – Whether to hide the cookie from JavaScript
Return type:

void

This helper function gives you friendlier syntax to set browser cookies. Refer to the Response Library for a description of its use, as this function is an alias for Response::setCookie().

get_cookie($index[, $xssClean = false])¶
Parameters:
  • $index (string) – Cookie name
  • $xss_clean (bool) – Whether to apply XSS filtering to the returned value
Returns:

The cookie value or NULL if not found

Return type:

mixed

This helper function gives you friendlier syntax to get browser cookies. Refer to the IncomingRequest Library for detailed description of its use, as this function acts very similarly to IncomingRequest::getCookie(), except it will also prepend the $cookiePrefix that you might’ve set in your application/Config/App.php file.

delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])¶
Parameters:
  • $name (string) – Cookie name
  • $domain (string) – Cookie domain (usually: .yourdomain.com)
  • $path (string) – Cookie path
  • $prefix (string) – Cookie name prefix
Return type:

void

Lets you delete a cookie. Unless you’ve set a custom path or other values, only the name of the cookie is needed.

delete_cookie('name');

This function is otherwise identical to set_cookie(), except that it does not have the value and expiration parameters. You can submit an array of values in the first parameter or you can set discrete parameters.

delete_cookie($name, $domain, $path, $prefix);
Next Previous

© Copyright 2014 - 2017, British Columbia Institute of Technology. Last updated on Jan 03, 2017.

Built with Sphinx using a theme provided by Read the Docs.