PHP Settings and get cookies
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 expiration 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, -);
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