Usage analysis of cookie method in thinkphp3.x _php instance

Source: Internet
Author: User
Tags php template set cookie smarty template

This article analyzes the use of cookie methods in thinkphp3.x. Share to everyone for your reference, specific as follows:

One, the cookie function is also a multiplication operation function, completes the cookie to set up, obtains and deletes the operation.

Cookies are used for cookie setup, fetch, and delete operations:

Usage:

Cookies ($name, $value = ', $option =null)

Parameters:

Name (required): Cookie variable to manipulate

Value (optional): The cookie value to set

Option (optional): Incoming cookie settings parameter, default is NULL

The return value is detailed (returns a different value according to the specific usage)

Second, cookie settings

Cookie (' name ', ' value '); Set Cookie cookie
(' 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_

Cookie (' 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 no incoming or incoming null values are passed in. _domain four configuration parameters. If only the individual parameters are passed in, they are also merged with the default configuration parameters.

Third, Cookie acquisition

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 ']

Four, 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 currently set prefix;//empty all cookie values for the specified prefix

PS: Here recommend a few of the format of this site landscaping tools, I believe that we can use in future development:

PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat

JavaScript code Landscaping/compression/formatting/encryption Tools:
http://tools.jb51.net/code/jscompress

Online XML format/compression tools:
Http://tools.jb51.net/code/xmlformat

JSON Code Formatting Landscaping tool:
Http://tools.jb51.net/code/json

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

SQL code Online formatting Landscaping tools:
Http://tools.jb51.net/code/sqlcodeformat

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Common Methods Summary", "PHP Cookie Usage Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.