2

我有一个带有 IP 插件位置的 Magento 站点。它大量使用cookies。因此,我需要清除所有 cookie magento 集。我有我认为正确的代码,但它不起作用:

$cookies = Mage::getModel('core/cookie')->get();
foreach($cookies as $cookie)
{
     Mage::getModel('core/cookie')->delete($cookie->name, $cookie->path);   
}

一些 cookie 设置在路径 '/' 上,一些设置在 /another' 上。我想清除所有内容以避免任何混淆。

关于如何做到这一点的任何想法?谢谢!

4

2 回答 2

2

您收到错误消息,因为 $cookie->name 和 $cookie->path 不是对象。要让你的循环工作,试试这个。

$names = Mage::getModel('core/cookie')->get(); //This returns an array of all cookies
foreach($names as $name) { //loop through the array
    $cookie = Mage::getModel('core/cookie')->get($name); //get the cookie object for each cookie
    $path = $cookie->getPath(); //get the path for the cookie

    Mage::getModel('core/cookie')->delete($name, $path); //delete that cookie
}
于 2014-01-15T18:50:58.937 回答
0

您也需要清除会话,例如

Mage::getSingleton('checkout/session')->unsetAll();

看看Mage_Persistent_IndexController::unsetCookieAction()(store.com/persistent/index/unsetCookie/)

于 2013-09-24T17:12:42.637 回答