thinkphp Development Framework function Detailed: Cookie method

Source: Internet
Author: User
Keywords Development framework functions cookie methods thinkphp
Tags aliyun array configuration parameters cookie cookie methods cookies default delete

The cookie function is also a multiplication function that completes the cookie setup, fetch, and delete operations.

Cookies are used to http://www.aliyun.com/zixun/aggregation/12583.html ">cookie settings, FETCH, delete operations use cookies ($name, $value = ', $option = NULL) parameter name (required): Cookie variable to manipulate
Value (optional): The cookie value to set
Option (optional): Incoming cookie setting parameters, default null return value See details (return different values according to the specific usage)

Cookie settings

Cookie (' name ', ' value '); Set Cookiecookie (' name ', ' value ', 3600); Specify Cookie Save time

Starting with version 3.1, the cookie method adds support for the array (using a lightweight JSON encoding format to save storage space), for example:

Cookies (' name ', Array (' name1 ', ' name2 '));

You can also support the way parameters are passed in to complete a complex cookie assignment, the following is a 3,600-second validity period for the cookie value, plus a cookie prefix THINK_

Cookies (' name ', ' value ', Array (' Expire ' =>3600, ' prefix ' => ' think_ '))

Array parameters can take the form of query argument

Cookie (' name ', ' value ', ' expire=3600&prefix=think_ ')

is equivalent to the above usage.
The option parameter passed in supports Prefix,expire,path,domain four index parameters, and Cookie_prefix, Cookie_expire, Cookie_path, and cookies are taken by default if there are no incoming or incoming null values _domain four configuration parameters. If only the individual parameters are passed in, they are also merged with the default configuration parameters.

Cookies get

Getting cookies is very simple, regardless of how the cookie is set up, you only need to use:

$value = Cookie (' name ');

If the cookie prefix is not set, the equivalent

$value = $_cookie[' name ']

If the cookie prefix is set, the equivalent

$value = $_cookie[' prefix +name ']

Cookie deletion

Deletes the value of a cookie by using:

Cookie (' name ', null);

To remove all cookie values, you can use the

Cookie (NULL); Clears all cookie value cookies (null, ' THINK_ ') for the current prefix; Empty all cookie values for the specified prefix
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.