【问题标题】:block access to page Zend Framework阻止对页面 Zend Framework 的访问
【发布时间】:2015-03-09 05:27:52
【问题描述】:

我已经使用 Zend Framework 为我的网站创建了登录页面,它可以正常工作。
在页面 A (www.example.com/a) 中,用户必须登录系统,如果用户名和密码匹配,则用户转到页面 B,C,..(www. example.com/b)
但是如果有人直接插入一个链接 (www.example.com/b) ,它可以看到页面 B ,没有任何权限,如何修复它?

【问题讨论】:

    标签: php zend-framework user-permissions


    【解决方案1】:

    我没有使用过 Zend,但可以在 Laravel 中使用路由中的过滤器 'before: auth' 简单地完成。

    Route::get('b', ['before'=>'auth', function() {
        //return your View here
    }]);
    

    这样在直接通过URL访问页面'b'之前,系统会检查用户是否通过了身份验证,如果没有,则会显示错误页面。

    您可以参考 Zend_Auth API 了解 Zend 中的实现细节,类似:

    http://framework.zend.com/manual/1.12/en/zend.auth.introduction.html http://framework.zend.com/manual/current/en/user-guide/routing-and-controllers.html

    【讨论】:

      【解决方案2】:

      你可以使用插件。

      例如,您可以尝试这样的操作:

      在您的引导程序中,添加此函数(以声明插件)

      public function _initPlugins(){
          $front = Zend_Controller_Front::getInstance();
          $front->registerPlugin(new Application_Plugin_PRoutage());
      }
      

      在此示例中,在 application/plugins 文件夹中,像这样创建 PRoutage.php 插件:

      class Application_Plugin_PRoutage extends Zend_Controller_Plugin_Abstract
      {
          public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
          {  
              if ( FALSE === Zend_Auth::getInstance()->hasIdentity()) 
              {  
                  // Redirection to login page
                  $request->setControllerName('login')
                           ->setActionName('login')
                           ->setDispatched(true) ;
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-23
        • 1970-01-01
        • 2017-09-23
        • 2017-09-02
        • 2017-08-01
        • 2016-11-01
        • 1970-01-01
        相关资源
        最近更新 更多