This repository was archived by the owner on Dec 8, 2022. It is now read-only.
forked from mako-framework/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Learn more: Cookies
Marco Montalbano edited this page Jul 31, 2017
·
1 revision
The cookie class provides a simple and consistent way to set and read cookies. All cookies set using the Cookie class will be signed.
The benefit of using signed cookies over regular cookies is that their values can not be tampered with on the client site.
Setting a signed cookie is done by using the set method. The available options are path, domain, secure and httponly.
// Sets signed a cookie that will expire when the browser closes.
Cookie::set('foobar', 'my value');
// Sets signed a cookie that will expire after 10 hours
Cookie::set('foobar', 'my value', (3600 * 10));
// Sets a signed "httponly" cookie that will expire after 10 hours
Cookie::set('foobar', 'my value', (3600 * 10), array('httponly' => true));
Reading a signed cookie is done using the get method. Unsigned cookies or cookies with an invalid signature will be ignored.
// Reads the 'foobar' cookie. If the cookie doesn't exist then $value will be set to NULL
$value = Cookie::get('foobar');
// Reads the 'foobar' cookie. If the cookie doesn't exist then $value will be set to '1234'
$value = Cookie::get('foobar', '1234');
Deleting cookies is done by using the delete method.
Cookie::delete('foobar');
// You can also set options when deleting cookies
Cookie::delete('foobar', array('httponly' => true));
- Getting started: Installation
- Getting started: Configuration
- Getting started: Error handling
- Getting started: Constants
- Getting started: Coding standards
- Controllers: Controllers
- Controllers: Request
- Controllers: Response
- Databases: Basics
- Databases: Query builder
- Databases: Orm
- Databases: Migrations
- Command line: Basics
- Command line: Custom tasks
- Packages: Basics
- Packages: Composer packages
- Learn more: Array helper
- Learn more: Asset manager
- Learn more: Autoloading
- Learn more: Caching
- Learn more: Cookies
- Learn more: Events
- Learn more: File helper
- Learn more: Html helper
- Learn more: Internationalization
- Learn more: Logging
- Learn more: Number helper
- Learn more: Pagination
- Learn more: Redis client
- Learn more: Rest client
- Learn more: Security helpers
- Learn more: Sessions
- Learn more: String helper
- Learn more: Url helper
- Learn more: Uuid helper
- Learn more: Validation
- Learn more: Views