This article analyzes the PHP creation, access cookies, and basic essentials. Share to everyone for your reference. Specifically as follows:
Suppose to be: cookie1.php file
Copy Code code as follows:
<?php
Setcookie ("name", "Baidu", Time () +60);
echo "Save Cookie";
?>
The required parameters are three:
(1) The first parameter: name is the key value, set yourself;
(2) The second parameter: the "Baidu" in the example indicates the value of the key value name;
(3) The third parameter: the Expiration Time () +60, which indicates that the expiration time is 60 seconds;
The cookie code parsing in the instance and the basic points
1, the browser to open cookie1.php, the server will be information: SET-COOKIE:NAME=%B0%D9%B6%C8; Expires=tue, 06-nov-2012 16:09:27 GMT (Note: This information is viewed using the grab kit) to respond to HTTP requests, which the client browser obtains and saves to the cookie file (different browsers and operating systems, Save location is not the same as file type
2. If the third time parameter is not set, the default is the end of the session (the browser is closed), and the cookie is invalidated (in this case, the cookie is saved in the browser cache).
3, cookies can only save string information, that is, objects can not be saved (session to save objects).
4, if the key value is Chinese, by default, the UrlEncode way, the Chinese to transfer code.
5, the cookie is saved, the clear way to save, so, save the password need to deal with, such as MD5.
6, can save multiple cookies.
7, the same page of different cookies, save time can be set differently.
8, a Web site should have a file to save cookies (if there is a set cookie).
Get cookies
File: cookie2.php
Copy Code code as follows:
<?php
echo "<pre>";
Print_r ($_cookie);
echo $_cookie[' name '];
?>
$_cookie is a predefined variable (array) that can be used to output cookies within the valid time of the cookie.
Knowledge Points: When visiting the cookie2.php page, the browser will send the cookies information to the server, which is stipulated by the HTTP protocol (can be viewed by grasping the package tool, as shown below)
I hope this article will help you with your PHP program design.