Home > Web Front-end > JS Tutorial > body text

What are cookies? What are cookies used for?

零下一度
Release: 2017-05-18 11:52:10
Original
2652 people have browsed it

Cookies provide a useful way for web applications to save information about users. For example, when a user visits your site, you can use cookies to save the user's preferences or other information so that the next time the user visits your site, the application can retrieve the previously saved information.

This article provides an overview of the use of Cookies in ASP.NET applications, showing you the technical details of applying Cookies in ASP.NET, such as writing Cookies and then reading them. At the same time, we will also introduce you to the various characteristics and special situations of Cookies, as well as ASP.NET's support for Cookies.

What are Cookies?

A cookie is a small piece of text information that is passed between a web server and a browser along with user requests and pages. The information contained in the cookie can be read by the web application each time the user visits the site.

Suppose that when a user requests to access a page on your website www.php.cn, your application sends not only a page to the user, but also a Cookie containing the date and time. . The user's browser also gets this cookie when getting the page, and saves it in a folder on the user's hard drive.

In the future, if the user visits a page on your site again, when the user enters the URL www.php.cn, the browser will look for the cookie associated with the URL on the local hard drive. If the cookie is present, the browser sends it to your site with the page request, and your application can determine the date and time the user last visited the site. You can send a message to the user based on this information, or you can check expiration times or perform other useful functions.

Cookies are associated with the Web site rather than with specific pages, so no matter which page in the site the user requests to browse, the browser and the server will exchange the cookie information of www.php.cn. When the user visits other sites, each site may send a cookie to the user's browser, and the browser saves all these cookies separately.

The above is the basic working principle of Cookie.

So, what are the uses of cookies?

The most fundamental purpose of cookies is to help Web sites save information about visitors. More generally, cookies are a way to maintain the continuity (that is, perform "state management") of a web application. The browser and the web server are always disconnected except for a brief period of actual information exchange, and each request a user sends to the web server is processed independently of all other requests. In most cases, however, it is necessary for the web server to recognize you when you request a page. For example, a Web server on a shopping site keeps track of each shopper so that the site can manage shopping carts and other user-related information. A cookie therefore acts like a business card, providing relevant identifying information that helps the application determine how to proceed.

Using cookies can serve a variety of purposes, all of which are designed to enable a website to remember you. For example, a site that implements a poll can simply use cookies as a Boolean value to indicate whether your browser has already participated in the poll, thus preventing you from voting again; while sites that require users to log in can use cookies to determine whether you have already participated in the poll. Logged in so you don't have to enter your credentials every time.

ASP.NET application The basics of Cookie programming are concepts that must be mastered.

Postscript:

Through the above popular science, I believe everyone understands the close relationship between Cookies and security. The editor recommends that you develop the habit of regularly clearing cookies. You can also use software to set up and clear cookies. This will not only improve the system's operating speed, but also ensure that some personal private information is not leaked.

[Related recommendations]

1. Detailed explanation of Js operation Cookie (setting, reading, deleting) examples

2. How to disable cookies and solve the problem of session and cookie destruction after closing the browser

The above is the detailed content of What are cookies? What are cookies used for?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!