循环所有Magento Cookies&删除

时间:2013-09-24 16:34:43

标签: php magento cookies

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

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

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

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

2 个答案:

答案 0 :(得分:2)

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

$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
}

答案 1 :(得分:0)

您也需要清除会话,例如

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

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