PHP Settings and get cookies

Source: Internet
Author: User
Tags setcookie

Setcookie (' MyCookie ', ' value ');
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) Call Setcookie () with the name parameter only;
(2) to make the expiry time () or time-1;

<?php Setcookie (' name ');?>

Setcookie (' MyCookie '), or Setcookie (' MyCookie ', '), or Setcookie ("MyCookie", false);
Setcookie (' MyCookie ', ', Time ()-3600);
Echo ($HTTP _cookie_vars[' MyCookie ');
Print_r ($_cookie);

Suggested removal method:
Setcookie (' MyCookie ', ', Time ()-3600);

PHP provides a very useful function mktime ().
You simply send the order to Mktime () the hour, minute, number of seconds, month, date, and year that you wish to represent,
Mktime () returns the total number of seconds that date has been since January 1, 1970.
Therefore, if you need to simulate Y2K problems:
$y 2k = mktime (0,0,0,1,1,2000);
Setcookie (' name ', ' value ', $y 2k);
Setcookie (' name ', ' value ', time+3600);
Setcookie (' name ', ' value ', $y 2k, ' ~/myhome ', '. domain.com ');

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.

PHP Settings and get cookies

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.