Overview: A cookie is a fragment of information that a server sends to the client, stored in the client's browser's memory or on the hard disk, and sent back to the client in a request to the server.
Role: is to record the user's data on the client, do not need to connect to the server again, then through the network transmission processing these data, improve the efficiency of Web page processing.
Example: When a user is authenticated on a Web page, the PHP script sets the relevant information in the form of a key-value pair to the client's cookie, which is sent to the client via HTTP response header information, and when another PHP script is accessed from the same server again, will be accessed with the data in the cookie (the header via the HTTP request ). This way, you do not need to re-enter the information of the login when you visit each page.
Second, cookie-based user login module
<?PHPfunctionClearCookie () {Setcookie(' username ', ', Time()-3600); Setcookie(' IsLogin ', ', Time()-3600); } if($_get["Action"]== "login") {ClearCookie (); if($_post["username"]== "admin" &&$_post["Password"]== "12345") { Setcookie(' username ',$_post["username"], Time() +60*60*24*7); Setcookie(' IsLogin ', 1, Time() +60*60*24*7); Header("Location:index.php"); } Else { die("User name and password error");}}ElseIf($_get["Action"]== "logout") {ClearCookie (); }?>Session Control--cookie