What are the functions and uses of cookies in PHP?

Source: Internet
Author: User
Features of Cookies

Cookies are generated by the server and sent to User-agent (typically a browser), and the browser saves the key/value of the cookie to a text file in a directory, The next time you request the same Web site, the cookie is sent to the server (provided the browser is set to enable cookies). The cookie name and value can be defined by the server side, so that the server can know whether the user is a legitimate user and whether a login is required, etc., and the server can set or read the information contained in the cookie to maintain the state of the user and the server session

The WEB server can filter or maintain this information through the information contained in the Cookie to determine the status in the HTTP transmission.

Cookies are commonly used in the following 3 areas:

Record certain information about a visitor. Cookies can be used to record the number of times a user visits a webpage, or to record information that may have been entered. In addition, some websites can use cookies to automatically record the user name of a guest who last logged in.

Pass a variable between pages. The browser does not save any variable information on the current page, and all variable information on the page disappears when the page is closed. If the user declares a variable id=6, to pass the variable to another page, you can save the variable ID as a cookie and then fetch the value of the variable by reading the cookie on the next page.

Storing the Internet pages you view in a Cookie temp file can increase the speed of your browsing later.

Note: Generally do not use cookies to save data sets or other large amounts of data. Not all browsers support cookies, and the data information is stored in clear text in the client computer, so it is best not to save sensitive, unencrypted data, otherwise it will affect the security of the network.

What are the uses of cookies?

The most fundamental use is that cookies can help a Web site keep information about visitors. More generally, cookies are a way to maintain WEB application continuity (that is, to perform "state management"). Browsers and Web servers are always disconnected in addition to the ephemeral actual information exchange phase, and each request that the user sends to the Web server is handled separately, regardless of all other requests. In most cases, however, it is necessary to have the WEB server identify you when you request a page. For example, a WEB server on a shopping site tracks each shopper so that the site can manage the shopping cart and other user-related information. So a Cookie acts like a business card, and it provides relevant identifying information that can help the application determine how to proceed.

Cookies can be used for a variety of purposes, all of which are designed to keep your Web site in mind. For example, a site that implements a poll can simply use cookies as a Boolean value to indicate whether your browser has participated in a poll to prevent you from repeating the poll, and those sites that require users to sign in can use cookies to determine if you have logged in, so you don't have to enter credentials every time.

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.