【问题标题】:Cakephp 1.2.5 redirect not working in controllerCakephp 1.2.5 重定向在控制器中不起作用
【发布时间】:2017-10-07 13:50:57
【问题描述】:

我在 cakephp 1.2.5 中有一个应用程序,我正在尝试使用

在另一个函数中重定向
$this->redirect(array('controller'=>'controller','action'=>'action'));

在重定向之前我的网站 url 是 https://example.com/controller/action 但在重定向后它更改为非 ssl 像 http://example.com/controller1/action 我如何重定向到 ssl

如果有人有任何想法,请帮助我。

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    使用安全组件通常在控制器 beforeFilter() 中完成。您可以指定所需的安全限制,安全组件将在其启动时强制执行:

    class AppController extends Controller {
        // Add security component
        public $components = array('Security');
    
        public function beforeFilter() {
            $this->Security->blackHoleCallback = 'forceSSL';
            $this->Security->requireSecure();
        }
    
        // Add this function in your AppController
        public function forceSSL() {
            return $this->redirect('https://' . env('SERVER_NAME') . $this->here);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-26
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多