This article mainly introduces how to use cookies in PHP in a timely manner. If you need them, please refer to them and hope to help you.
This article mainly introduces how to use cookies in PHP in a timely manner. If you need them, please refer to them and hope to help you.
Generally, php requires a browser click to generate a cookie. How can we make the cookie take effect in a timely manner? Here is a method to make the cookie take effect in a timely manner. The Code is as follows:
The Code is as follows:
/**
* Set cookie
* @ Param string $ name key name
* @ Param mixed $ value
* @ Param int $ expire expiration time. The default value is one day.
*/
Public final function setCookie ($ name, $ value, $ expire = null ){
// If the cookie value is null, exit
If (empty ($ value) return;
// Expiration time
If (empty ($ expire) $ expire = time () + 86400;
$ _ COOKIE [$ name] = $ value;
// Determine whether the value is an array.
If (is_array ($ value )){
Foreach ($ value as $ k => $ v ){
If (empty ($ v) continue;
Setcookie ($ name. "[$ k]", $ v, $ expire );
}
} Else {
Setcookie ($ name, $ value, $ expire );
}
}
,