Home >Backend Development >PHP Tutorial >PHP creates, obtains cookies and analyzes basic points, phpcookie_PHP tutorial
This article analyzes PHP creation, obtaining cookies and basic points with examples. Share it with everyone for your reference. The details are as follows:
Assume: cookie1.php file
(1) The first parameter: name is the key value, set it yourself;
(2) Second parameter: "Baidu" in the example represents the value corresponding to the key value name;
(3) The third parameter: indicates the expiration time, time()+60, which indicates the expiration time is 60 seconds;
Cookie code analysis and basic points in the example
1. When the browser opens cookie1.php, the server will send the message: Set-Cookie:name=%B0%D9%B6%C8; expires=Tue, 06-Nov-2012 16:09:27 GMT (Remarks : Please use the packet capture tool to view this information) to respond to the http request. The client browser obtains this information and saves it in the cookie file (different browsers and operating systems have different storage locations and file types)
2. If the third time parameter is not set, the cookie will expire when the session ends (close the browser) by default (in this case, the cookie is stored in the browser cache).
3. Cookies can only save string information, that is, objects cannot be saved (session can save objects).
4. If the key value is Chinese, the urlencode method is used by default to transcode the Chinese.
5. When the cookie is saved, it is saved in clear text, so the password needs to be processed, such as md5.
6. Multiple cookies can be saved.
7. Different cookies on the same page can be saved for different times.
8. A website corresponds to a file that saves cookies (if cookies are set).
Get cookies
File: cookie2.php
";
print_r($_COOKIE);
echo $_COOKIE['name'];
?>
I hope this article will be helpful to everyone’s PHP programming design.