Logo
  • CodeIgniter4へようこそ
    • CodeIgniter4へようこそ
    • Server Requirements
    • Credits
    • PSR Compliance
  • Installation
    • Manual Installation
    • Composer Installation
    • Running Your App
    • Upgrading From a Previous Version
    • Troubleshooting
    • CodeIgniter Repositories
  • Build Your First Application
    • Static pages
    • News section
    • Create news items
    • Conclusion
  • CodeIgniter4 概要
    • Application Structure
    • Models, Views, and Controllers
    • Autoloading Files
    • Services
    • HTTP リクエストを利用した作業
    • Security Guidelines
  • General Topics
    • Configuration
    • CodeIgniter URLs
    • Helper Functions
    • Global Functions and Constants
    • Logging Information
    • Error Handling
    • Web Page Caching
    • AJAX Requests
    • Code Modules
    • Managing your Applications
    • Handling Multiple Environments
  • Controllers and Routing
    • Controllers
    • URI Routing
    • Controller Filters
    • HTTP Messages
    • Request Class
    • IncomingRequest Class
    • Content Negotiation
    • HTTP Method Spoofing
    • RESTful Resource Handling
  • Building Responses
    • Views
    • View Cells
    • View Renderer
    • View Layouts
    • View Parser
    • HTML Table Class
    • HTTP Responses
    • API Response Trait
    • Localization
    • Alternate PHP Syntax for View Files
  • Working With Databases
    • 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
    • Database Events
    • Database Utilities
  • Modeling Data
    • Using CodeIgniter's Model
    • Using Entity Classes
  • Managing Databases
    • Database Manipulation with Database Forge
    • Database Migrations
    • Database Seeding
  • Library Reference
    • Caching Driver
    • CURLRequest Class
    • Email Class
    • Encryption Service
    • Working with Files
    • Honeypot Class
    • Image Manipulation Class
    • Pagination
    • Security Class
    • Session Library
    • Throttler
    • Dates and Times
    • Typography
    • Working with Uploaded Files
    • Working with URIs
    • User Agent Class
    • Validation
  • Helpers
    • Array Helper
    • Cookie Helper
    • Date Helper
    • Filesystem Helper
    • Form Helper
    • HTML Helper
    • Inflector Helper
    • Number Helper
    • Security Helper
    • Test Helper
    • Text Helper
    • URL Helper
    • XML Helper
  • Testing
    • Getting Started
    • Database
    • Generating Data
    • Controller Testing
    • HTTP Testing
    • Benchmarking
    • Debugging Your Application
  • Command Line Usage
    • Running via the Command Line
    • Custom CLI Commands
    • CLI Library
    • CLIRequest Class
  • Extending CodeIgniter
    • Creating Core System Classes
    • Replacing Common Functions
    • Events
    • Extending the Controller
    • Authentication
    • Contributing to CodeIgniter
CodeIgniter
  • »
  • Helpers »
  • Cookie Helper

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 app/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 2019-2020 CodeIgniter Foundation Last updated on Jul 05, 2020.

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