0

我刚刚将我的应用程序上传到共享托管环境中,但它似乎无法正常工作。我注册了 2 个插件。一个检查会话超时,另一个检查会话是在登录后创建的。问题是在第二个插件(security.php)启动后,它假设将用户重定向到登录屏幕,因为尚未创建会话。重定向后,页面显示:页面未正确重定向。我不确定发生了什么,因为在本地一切正常。下面是我在这里提到的两个文件。Security.php(在这里你可以看到我尝试了几个选项,但没有任何效果)。

class Plugins_security extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch (Zend_Controller_Request_Abstract $request)
    {
        $auth = Zend_Auth::getInstance();

        $moduleName = $request->getModuleName();
        //$vc = new Zend_Application_Resource_View();
        if ($request->getModuleName() != "auth")
        {
            $auth = Zend_Auth::getInstance();
            if (! $auth->hasIdentity())
            {
                //$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper(
                //'redirector');
                $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
                $flashMessenger->addMessage(array('message' => 'Sua sessão expirou. Favor logar novamente', 'status' => 'info'));
                //$this->_redirect('/auth/login/',array(‘code’ => 301));

                $r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                $r->gotoSimple("index", "login", "auth");
                //header('Location: /auth/login/'); 
                //return;
            }
        }
    }
}

超时.php

class Plugins_timeout extends Zend_Controller_Plugin_Abstract
{
    protected $_auth = null;
    protected $_acl = null;
    protected $_flashMessenger = null;
    protected static $_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS= 900;



    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
    Zend_Session::start();
    $moduleName = parent::getRequest()->getModuleName();
    if($moduleName !='auth'){
    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS)) {
    // last request was more than 30 minates ago
    session_destroy();   // destroy session data in storage
    session_unset();     // unset $_SESSION variable for the runtime

    $front = Zend_Controller_Front::getInstance();
    $_baseUrl=$front->getBaseUrl();
    Zend_Debug::dump(time() - $_SESSION['LAST_ACTIVITY']);
    header("Location:$_baseUrl/auth/login/index/timeout/1" );

    }else{
            $_SESSION['LAST_ACTIVITY']= time();
        }
    }   
    }

}

任何帮助表示赞赏。我需要尽快部署这个应用程序。谢谢你。

4

1 回答 1

0

我想你想要:

$r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$r->gotoSimpleAndExit("index", "login", "auth"); // Note the 'AndExit' suffix.

$r->gotoXXX()只是在对象中设置正确的标头和代码$response,但允许其余的调度继续。相反,该AndExit部分立即将响应发送给客户端并退出。

[不清楚为什么AndExit在您的本地环境中不需要,但是...]

于 2013-05-31T03:36:08.667 回答