php cookie不刷新及时生效的实现代码

<?php
/**
 * 不刷新 cookie及时生效
 */
cookie("mycookie","cookievalue",time()+60); 
cookie("mydemo",array('name'=>"demovalue_1",'address'=>"demovalue_2"),time()+60); 
var_dump($_COOKIE["mycookie"]);  
var_dump($_COOKIE["mydemo"]);    
      
//PHP COOKIE设置函数立即生效,支持数组  
function cookie($var, $value='', $time=0, $path='', $domain='')  
{  
    $_COOKIE[$var] = $value;  
    if(is_array($value)){  
       foreach($value as $k=>$v){  
          setcookie($var.'['.$k.']', $v, $time, $path, $domain, 0);  
        }  
    }else{  
        setcookie($var, $value, $time, $path, $domain, 0);  
     }  
}
?>

 

posted @ 2015-07-23 15:01  壁虎漫步.  阅读(396)  评论(0编辑  收藏  举报