Session Control--cookie

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.