如果键在PHP中以X开头,请删除Cookie [英] Delete a cookie if the key start by X in PHP

查看:206
本文介绍了如果键在PHP中以X开头,请删除Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由XYZ开始的cookie,我想在用户访问特定路由时取消设置。

I got some cookie start by XYZ and I want to unset them when the user access to a specific route.

所以我的代码:

foreach ($_COOKIE as $key => $value)
        if (preg_match('/^XYZ/', $key))
            unset($_COOKIE[$key]);

但cookie仍然存在。
我真的不明白,因为当我做:

But the cookies still there. I really don't understand because when I do :

foreach ($_COOKIE as $key => $value)
        if (preg_match('/^XYZ/', $key))
            echo($_COOKIE[$key]);

...它工作。

推荐答案

重置Cookie,例如:

reset a cookie like:

setcookie($key,"",time()-3600);

这篇关于如果键在PHP中以X开头,请删除Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆