后台key值至关重要,关系着是否能够访问后台页面
获取到key值:Mage::getSingleton('adminhtml/url')->getSecretKey();
其实是$controller . $action. $salt拼接后获取到hash值
public function getSecretKey($controller =null, $action = null)
{
$salt = Mage::getSingleton('core/session')->getFormKey();
$p = explode('/', trim($this->getRequest()->getOriginalPathInfo(),'/'));
if (!$controller) {
$controller = !empty($p[1]) ? $p[1] :$this->getRequest()->getControllerName();
}
if (!$action) {
$action = !empty($p[2]) ? $p[2] :$this->getRequest()->getActionName();
}
$secret = $controller . $action . $salt;
return Mage::helper('core')->getHash($secret);
}
自定义的函数:
public function getSecretKey($controller,$action)
{
$salt = Mage::getSingleton('core/session')->getFormKey();
$secret = $controller . $action . $salt;
return Mage::helper('core')->getHash($secret);
}
Magento后台Key生成机制
本文介绍了Magento中后台访问密钥的生成方法,包括默认的密钥生成逻辑及自定义函数实现。通过理解$controller.$action.$salt的拼接与hash转换过程,可以更好地管理后台的安全访问。

被折叠的 条评论
为什么被折叠?



