【问题标题】:Zend Framework redirect in front controller plugin causes redirect loop前端控制器插件中的 Zend Framework 重定向导致重定向循环
【发布时间】:2011-12-21 06:22:32
【问题描述】:
class Ef_AppSecurity extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        if (!Zend_Auth::getInstance()->getIdentity())
        {
            $redirect = new Zend_Controller_Action_Helper_Redirector();
            $redirect->gotoSimpleAndExit('login', 'auth');
        }
    }
}

它会重定向并更改到新的 url,但是在浏览器中它会创建一个重定向循环。我想知道问题是否源于 apache mod_rewrite 设置。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

【问题讨论】:

    标签: php zend-framework redirect apache2


    【解决方案1】:

    不要在登录/验证时附加该插件,;将标准扩展到

    if (!Zend_Auth::getInstance()->getIdentity()
         && $this->getRequest()->getControllerName() != 'login'
         && $this->getRequest()->getActionName() != 'auth')
    

    【讨论】:

    • @eforth 很高兴我能帮上忙!随意将任何答案标记为“正确”以使“案例关闭”。
    【解决方案2】:

    您必须为登录页面添加一个例外。否则,它也会被重定向回自身,从而导致循环。

    因此,如果您的登录页面位于名为“登录”和“索引”操作的控制器中,则您需要为该页面添加一个异常,并且任何其他可能处理该表单的页面。

        if (!Zend_Auth::getInstance()->getIdentity() 
            && $this->getRequest()->getControllerName() != 'login'
            && $this->getRequest()->getActionName() != 'index')
            )
        {
            $redirect = new Zend_Controller_Action_Helper_Redirector();
            $redirect->gotoSimpleAndExit('login', 'index');
        }
    

    【讨论】:

    • 这正是我发布的内容吗?除非你操作错误。
    • 感谢 paulrichards19 解释了为什么我得到了循环。
    猜你喜欢
    • 1970-01-01
    • 2015-11-09
    • 2016-06-15
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多