How PHP cookies take effect in a timely manner

Source: Internet
Author: User
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 );
}
}

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.