cookie(null)没有设置前缀时无法清空cookie

浏览:1527 发布日期:2014/12/22
3.2.2 - 普通 - 未处理
当没有设置cookie前缀时使用cookie(null)无法清除cookie,目前本人解决方法为:
修改Thinkphp/Common/functions.php中的cookie()方法
// 清除指定前缀的所有cookie
if (is_null($name)) {
if (empty($_COOKIE))
return;
// 要删除的cookie前缀,不指定则删除config设置的指定前缀
$prefix = empty($value) ? $config['prefix'] : $value;
if (!empty($prefix) || null == $name) {// 如果前缀为空字符串将不作处理直接返回//
//增加 null ==$name判断
foreach ($_COOKIE as $key => $val) {
if (0 === stripos($key, $prefix) || null == $name) {//增加 null ==$name判断
setcookie($key, '', time() - 3600, $config['path'], $config['domain']);
unset($_COOKIE[$key]);
}
}
}
return;
}
评论(
后面还有条评论,点击查看>>