How PHP reads COOKIES

Source: Internet
Author: User
Check the browser's Cookies. let's take a look at the content stored in the browser. if you use IE5, there is a cookie directory under the windows directory, which contains a lot of text

View browser Cookies

Let's take a look at the content stored in the browser. if you use IE5, there is a cookie directory under the windows directory, which contains many text files, the file names are similar to wudong@15seconds%1%.txt. this is the cookie used by the browser to save the value. in earlier IE versions, the cookies can be viewed, but now the content has been encoded. before the browser obtains a Web page, it will first check the domain name of the page and whether it exists in the cookie, the browser sends the matching cookie to the server before accepting the page sent by the server.

Here is an example of a cookie application: when I connect to Amazon.com, the browser sends the previously set cookies to Amazon before accepting the first page, then, Amazon.com checks the transmitted content to see if there is any relevant information in the database. after matching, a custom page is created for me and sent to it.

Assign values to cookies,The cookie must be assigned a value before the server sends any content to the client browser.Label:

  1. <? Php
  2. Setcookie ("CookieID", $ USERID );
  3. ?>
  4. <HTML>
  5. <BODY>
  6. </BODY>
  7. </HTML>

The setcookie function has six parameters separated by commas:

The cookie name is a string, for example, "CookieID", which cannot contain colons, commas, and spaces. this parameter is required, and all other parameters are optional, if only this parameter is provided, the cookie will be deleted.

The cookie value is usually a string variable. for example, $ USERID can also be assigned a question mark ?? To skip the value setting.

The time when the cookie expires. If it is omitted (or assigned to zero value), the cookie will expire after the session ends. This parameter can be an absolute time, represented by DD-Mon-yy hh: MM: SS, for example, "24-Nov-99 08:26:00 ". It is more commonly used to set a relative time. This is implemented through the time () function or the mktime function. For example, time () + 3600 will invalidate the cookie after one hour.

A path used to match the cookie. When multiple cookie settings with the same name exist on a server, this parameter is required to avoid confusion. The effect of using the "/" path is the same as that of omitting this parameter. Note that the cookie definition of Netscape places the domain name in front of the path, while PHP is opposite.

The server domain name is also used to match the cookie. Note that a point (.) must be placed before the domain name of the server (.). For example, ".friendshipcenter.com ". Because the parameter is unacceptable unless more than two vertices exist.

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.