Operation of Cookies in PHP

Source: Internet
Author: User
Tags setcookie

PHP Settings and get cookies

Create a cookie

Setcookie (' MyCookie ', ' value ', Time () +86400);//Parameter 3 cookie expiration
function prototypes: int Setcookie (string name,string value,int expire,string path,string domain,int Secure)

Echo ($mycookie);
Echo ($HTTP _cookie_vars[' MyCookie ');
Echo ($_cookie[' MyCookie ');

Delete Cookies
1) Setcookie (' name '); Call Setcookie () with the name parameter only;
2) Setcookie (' MyCookie ', ', ', Time ()-1); Make the expiry date () or Duration ()-1;

Ways to get the cookie expiration time
$expire = time () + 86400; Set the 24-hour validity period
Setcookie ("Var_name", "Var_value", $expire); Set a cookie named Var_name, and establish a validity period
Setcookie ("Var_name_expire", $expire, $expire); Then set the expiration time to a cookie so that you can know the expiration time of the Var_name

Note:
When a cookie is sent, the value of the cookie is automatically URL-encoded. The URL is decoded when it is received.
If you don't need this, you can use Setrawcookie () instead.

Operation of Cookies in PHP

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.