Introduction and use of PHP cookie principle ____php

Source: Internet
Author: User

Cookies are client-side technology, and the server writes each user's data to the user's browser in the form of a cookie. When users use the browser to access the server's Web resources again, they carry their own data, so that the Web resources handle the user's own data.

  

Some related actions of cookies:

  

Cookies are part of the HTTP header, so the Setcookie () function must be called before other information is exported to the browser.

If you do not set a time cookie that is not saved to the client, the cookie expires when the browser is closed.

The information that the cookie holds is actually a string.

The client can hold multiple key-value pairs.

Cookies can also be saved in Chinese and will be encoded in Chinese by default UrlEncode.

A cookie can have multiple key-value pairs that can be set to a valid time for different key-value pairs.

Browser to determine whether the cookie expires, the server in the setting of cookies, the browser will be informed of the validity of the cookie. When the browser sends a request to the server, it detects that the cookie is valid and only carries a special expiration value when the cookie data request is not valid.

The cookie is valid on the current path and its descendants path.

Note: path, not the local disk path of the file where the code resides, but the path relationship of the URL request.

Note: Different paths, cookies with the same name can be stored at the browser end.

When the browser makes a request, it will first find the valid cookie in the current directory, and then look up, will all valid, are carried to the server side, the server in the formation of $_cookie, will appear rewrite effect, the first occurrence of the reservation! can be passed Setcookie () The fourth parameter is modified: it is usually set to/indicates that the site root directory is valid. Which is the whole station.

Valid valid paths are also judged on the browser side.

Cookies are valid only under the current domain. You can set it by using the fifth parameter.

$_cookie only stores cookies that are carried when the browser requests it.

The cookie that is set within the current script cycle cannot exist in the $_cookie.

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.