Home >Backend Development >PHP Tutorial >PHP cookies deletion, assignment method_PHP tutorial
php tutorial cookies deletion, assignment method
Cookies are often used to identify users. Cookies are small files that a server leaves on a user's computer. Whenever the same computer requests a page through the browser, it also sends the cookie. With php you can create and retrieve cookie values
Grammar
setcookie(name, value, expire, path, domain);
**
* Set cookie
* n name
* c value
* e Validity period 0 Default is one month 1 Close and expire immediately
*/
function w_cookie($n, $c, $e = 0,$isdes=1)
{
if($isdes==1){$c=endes($c,deskey);}
$exp = time() + 3600 * 24 * 30;
If($e == 0)
{
setcookie($n, $c, $exp,"/");
}
else
{
setcookie($n, $c,0,"/");
}
}
//Close cookie method
w_cookie('bb', 'www.bKjia.c0m', $e = 0,$isdes=1);
For more details, please check: http://www.bKjia.c0m/phper/php/34040.htm
More detailed methods
function set_cronology($name,$value,$duration=7){
$duration=time()+(3600*24*$duration);
$max_stored_values=5;
if(isset($_cookie[$name])){
foreach($_cookie[$name] as $prop_crono=>$val_crono){
if($val_crono==$value)
return;
}
if($prop_crono<$max_stored_values)
setcookie($name.'['.($prop_crono+1).']',$value,$duration);
else{
array_shift($_cookie[$name]);
setcookie("$name[$max_stored_values]",$value,$duration);
}
}else
setcookie($name.'[0]',$value,$duration);
return;
}
?>
Note: The setcookie() function must be placed before the tag. The cookie value is automatically url-encoded when sending the cookie and automatically decoded when retrieved (to prevent url-encoding, use setrawcookie() instead).