PHP中的cookie不用刷新就生效的方法_php技巧

WBOY
Release: 2016-05-17 09:13:06
Original
949 people have browsed it

不过,这种机制总是会给我们带来这或那的问题,比如前段时间,我的站点上得设置一个广告显示的功能,就需要用到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开发笔记
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!