php cookie

setcookie(name,value,expire_time,path,domain,security);

name name
value value
Expiry − This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed.

Path − This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.

Domain − This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them.

Security − This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be sent by regular HTTP.

Example:

setcookie("name","cyany_blue");
sleep(1);
echo $_COOKIE["name"]."<br>";
echo time()."<br>";
setcookie("blue123","color123",time()+36000000,"/","","0");
if(isset($_COOKIE["name"])){
	echo $_COOKIE["name"];
}else{
	echo "not found!";
}
// if you want to delete cookie ,you can set exprie_time to pass time .
setcookie("name","456",time()-3600,"/","",0);
echo $_COOKIE["name"];

原文地址:https://www.cnblogs.com/cyany/p/10011974.html