Overview of Cookies for PHP Session Control

We gave a small example of a meeting before:

When people had meetings decades ago, they all needed to bring a participant with them. certificate. This participation card contains the person's position, name, unit, photo and other information. During a meeting, meeting security personnel and organizers only need to check relevant information.

This small example mainly illustrates the point that people bring their own participation cards and their own information. This pattern is the cookie.

The computer stores this cookie information in the computer's hard drive.

Where do cookies exist? The essence of a cookie is a small piece of data, a small piece of data stored on your computer's hard drive. But where does it exist? Come, let's look for it.

The storage path of the Chrome browser's Cookie file is:
C:\Users\your username\AppData\Local\Google\Chrome\User Data\Default\Cookies

The cookie file storage path of the Firefox browser is:
C:\Users\your username\AppData\Roaming\Mozilla\Firefox\Profiles\rdgp36vl.default\cookies.sqlite Everyone may be slightly different (PS:rdgp36vl .default This prefix may be PHP Academy).

Use a text editor to open the Cookies file directly and you will see garbled characters. We have to use tools to check it, as shown below:

2015-08-12_55cb4061d17e8.png

Let’s take a look and need to pay attention. Several columns, Domain represents the website to which the cookie belongs, Name represents the name of the cookie, Value represents the value of the cookie, and Expires represents the validity period of the cookie.

Take a familiar website as an example, tudou.com. In the picture we can see that there are 4 cookies about tudou.com. Then when we visit tudou.com, the browser will automatically The Name and Value of the 4 cookies are sent to the server pointed to by tudou.com (PS: must be within the validity period. If it exceeds the validity period, it will not be sent to the server. We can determine the validity period according to the needs). In this way , the server can maintain the connection with the client based on this information. In layman's terms, it can know that you are you through this data. When the server receives these cookies, it will do some processing based on their values. What processing will be done? It depends on what the developer wants to do with this information!

The above briefly introduces Cookies and their uses. Next we will learn to use
Cookies in PHP.


Continuing Learning
||
<?php setcookie('name'); setcookie('mycookie');或setcookie('mycookie','');或setcookie("mycookie",false); //setcookie('mycookie','',time()-3600); echo($HTTP_COOKIE_VARS['mycookie']); print_r($_COOKIE); ?>
submitReset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!