setcookie('mycookie','value'); //Function prototype: 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 Cookie (1) Call setcookie() with only name parameter; (2) Set the expiration time to time() or time-1;
setcookie('mycookie'); or setcookie('mycookie',''); or setcookie("mycookie",false); //setcookie('mycookie','',time()-3600); echo ($HTTP_COOKIE_VARS['mycookie']); print_r($_COOKIE);
Recommended deletion method: setcookie('mycookie','',time()-3600);
PHP provides a very useful function mktime(). You just need to pass to mktime() the hours, minutes, seconds, month, date, and year you want to represent in order, mktime() will return the total number of seconds since January 1, 1970 for the date. So if you need to simulate the Y2K problem: $y2k = mktime(0,0,0,1,1,2000); setcookie('name','value',$y2k); setcookie('name', 'value', time+3600); setcookie('name', 'value', $y2k, '~/myhome', '.domain.com');
How to get the COOKIE expiration time $expire = time() + 86400; // Set the validity period of 24 hours setcookie ("var_name", "var_value", $expire); // Set a cookie named var_name, and The validity period is set setcookie ("var_name_expire", $expire, $expire); // Then set the expiration time into the cookie so that you can know the expiration time of var_name
Note: When sending a cookie, the cookie value is automatically URL encoded. URL decoding occurs on reception. If you don’t need this, you can use setrawcookie() instead.
|