为CakePHP中的某些操作选择性启用SSL [英] Selectively enabling SSL for certain actions in CakePHP

查看:129
本文介绍了为CakePHP中的某些操作选择性启用SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试仅在基于CakePHP的网站上启用某些操作的SSL。我这样做使用requireSecure()和重定向到https:// url在相应的blackHoleCallback()。

I'm trying to enable SSL for only certain actions on my CakePHP based website. I'm doing this using requireSecure() and redirecting to https://url in the corresponding blackHoleCallback().

为了保持服务器负载,我想以在用户完成需要SSL的操作后重定向回 http:// whatever_url

To keep the server load down, I'd like to redirect back to http://whatever_url once the user is done with the action that requires SSL.

我如何做到这一点?

推荐答案

我在 AppController 中的 beforeFilter()添加以下代码段:

So this is one solution I've come upon. I add the following snippet to beforeFilter() in AppController:

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

函数定义为:

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

这篇关于为CakePHP中的某些操作选择性启用SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆