【问题标题】:Selectively enabling SSL for certain actions in CakePHP选择性地为 CakePHP 中的某些操作启用 SSL
【发布时间】:2009-04-15 11:44:38
【问题描述】:

我正在尝试为基于 CakePHP 的网站上的某些操作启用 SSL。我正在使用 requireSecure() 并在相应的 blackHoleCallback() 中重定向到 https://url

为了降低服务器负载,一旦用户完成需要 SSL 的操作,我想重定向回 http://whatever_url

我该怎么做?

【问题讨论】:

    标签: cakephp ssl https


    【解决方案1】:

    所以这是我遇到的一种解决方案。我在AppController 中将以下sn-p 添加到beforeFilter()

    if (!in_array($this->action, $this->Security->requireSecure) and env('HTTPS'))
        $this->_unforceSSL();
    

    函数定义为:

    function _unforceSSL() {
        $this->redirect('http://' . $_SERVER['SERVER_NAME'] . $this->here);
    }
    

    【讨论】:

      【解决方案2】:

      确保对安全页面使用需要安全连接的 cookie,对非安全页面使用普通 cookie。这样,如果有人捕获了不安全的 cookie,他们将无法劫持任何敏感信息。

      【讨论】:

        【解决方案3】:

        我不喜欢重定向方法的地方是用户仍然会访问不安全的 url,并且只有在此之后他才会被重定向。

        我想在 html->link/url 级别完成一些事情,根据您传递的内容返回 ssl/非 ssl 链接,类似于: http://cakephp.1045679.n5.nabble.com/Re-Login-through-HTTPS-on-CakePHP-td1257438.html 还要使用安全组件

        稍后编辑,我做了一些更简单的事情,刚刚完成了我的工作,我尝试创建一个简单的示例(不要忘记在 config/core.php 或 bootstrap.php 中定义 MYAPP_SECURE_URL) : 在应用程序中我创建了 app_helper.php:

        class AppHelper extends Helper {
            function url($url = null, $full = false) {
                if($url['action'] == 'login' && $url['controller'] == 'users') {
                    return MYAPP_SECURE_URL.'/users/login';
                }
                return h(Router::url($url, $full));
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2014-06-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多