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) ;?>