Setcookie for php functions

Source: Internet
Author: User
The setcookie function of php can be used to set a cookie. However, the cookie page set in php cannot be obtained for the first time. you must refresh the page for the second time.

This is because the cookie principle:

$ _ COOKIE array is the cookie value of the variable returned from the client. Therefore, when the page is executed for the first time, the cookie value of the client does not exist.

After refresh, the value passed by the server is executed for the second time. Therefore, you can obtain the value.

There is a work und to make the cookie value take effect without refreshing for the first time. In fact, it is to assign a value to the $ _ COOKIE array. the code is as follows:

 $ V) {setcookie ($ var. '['. $ k. ']', $ v, $ time, $ path, $ domain, $ s) ;}} else {setcookie ($ var, $ value, $ time, $ path, $ domain, $ s) ;}// var_dump ($ _ COOKIE) ;?>

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.