PHP的COOKIE在设定之后,必须要刷新一下网页才能生效,至于是什么原因,有人说是为了安全考虑,至于你信不信,反正我信了
不过,这种机制总是会给我们带来这或那的问题,比如前段时间,我的站点上得设置一个广告显示的功能,就需要用到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, $s);
}
}else{
setcookie($var, $value, $time, $path, $domain, $s);
}
}
//调用方法
cookie("website","WEB开发笔记","./","www.jb51.net");
//
echo $_COOKIE["website"];//输出WEB开发笔记
Statement: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