PHP COOKIE takes effect immediately and can be used without refreshing

WBOY
Release: 2016-07-25 08:46:44
Original
1202 people have browsed it
Usually, in php, such a piece of code requires the browser to refresh before the cookie can appear. How can I make the cookie take effect in time? I would like to share a method to make the cookie take effect in time. It is very practical. The code is as follows:
  1. //PHP COOKIE setting function takes effect immediately and supports arrays
  2. function cookie($var, $value=”, $time=0, $path=”, $domain=”){
  3. $_COOKIE[$ var] = $value;
  4. if(is_array($value)){
  5. foreach($value as $k=>$v){
  6. setcookie($var.'['.$k.']' , $v, $time, $path, $domain, $s);
  7. }
  8. }else{
  9. setcookie($var, $value, $time, $path, $domain, $s);
  10. }
  11. }
Copy code

In this way, you can get the cookie value directly without refreshing. Please see the php manual for cookie parameter details.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template