02-addition, deletion, modification, and query of cookies

Source: Internet
Author: User
<? PHP header ("Content-Type: text/html; charset = UTF-8"); // demonstrate how to update the cookie information setcookie ("password", "11111", time () + 300); echo "file updated successfully! ";?>

<? PHP // specify to delete a key-Value Pair // setcookie ("name", "", time ()-200); // echo "name deleted successfully! "; // Delete all cookies. If the cookie file does not have a record, the cookie file will also be // deleted foreach ($ _ cookie as $ key => $ Val) {setcookie ($ key, "", time ()-100);} echo "successfully deleted all localhost cookies! ";?>

<? PHP header ("Content-Type: text/html; charset = UTF-8 "); // demonstrate how to create cookie information // Save the user name and password to the client's cookie // This function is used to save the cookie, the first // parameter represents the parameter's key value, the second value indicates the cookie value. // 3 indicates the expiration time, in seconds. Setcookie ("name", "shunping", time () + 3600); setcookie ("password", "12345", time () + 3600); echo "saved successfully! ";?>

<? PHP header ("Content-Type: text/html; charset = UTF-8"); // demonstrate how to obtain cookie information echo "<PRE> "; // obtain all cookieprint_r ($ _ cookie); echo "</PRE> "; // obtain the value of the specified key $ name =$ _ cookie ['name']; echo "name = ". $ name;?>

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.