简体   繁体   English

php cookie相关问题

[英]php cookies related issue

i create a cookies as 我创建一个饼干

setcookie('sm_posts['.$key.']', 'value', time()+60*60*24*365); 

for an array sm_posts and print these cookies in a wordpress page but if i click on a cross image then it will be delete but it is not working 为数组sm_posts并在wordpress页面中打印这些cookie,但是如果我单击交叉图像,则将其删除但无法正常工作

foreach($_COOKIE["sm_posts"] as $key => $value)      
{
    setcookie('sm_posts['.$key.']', '', time()-60*60*24*365);           
}

please help 请帮忙

Try specifying the path as the next parameter. 尝试将路径指定为下一个参数。

setcookie('sm_posts['.$key.']', '', time()-60*60*24*365, '/');

Do this for BOTH cookie settings statements (and manually delete all your existing cookies). 对两个Cookie设置语句都执行此操作(并手动删除所有现有的Cookie)。


But a better solution is to use the WordPress defines for this, COOKIEPATH and COOKIE_DOMAIN. 但是更好的解决方案是为此使用WordPress定义的COOKIEPATH和COOKIE_DOMAIN。

setcookie('sm_posts['.$key.']', '', time()-60*60*24*365, COOKIEPATH, COOKIE_DOMAIN);

(Again, manually delete all the existing cookies) (再次,手动删除所有现有的cookie)

Try it this way 这样尝试

foreach($_COOKIE["sm_posts"] as $key => $value)
 {
    setcookie ("sm_posts['".$key."']","", time()-60*60*24*365);
 }

I think it because of your quotes 我认为是因为您的报价

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM