2

我了解如何在某些页面上强制使用 SSL,但如何在没有 https 连接的情况下重定向其他页面?

原因是我在其他页面上运行了外部 javascript 和图像,它们不需要是安全的,但是它使用 https 从我的安全支付页面重定向,并在其上创建带有红十字的挂锁。

谢谢

4

1 回答 1

3

Cake Book 有一个如何强制 SSL 的示例

public function forceSSL() {
    $this->redirect('https://' . env('SERVER_NAME') . $this->here);
}

forceSSL()函数用于 SecurityComponent 的回调,如果在没有 https 的情况下访问页面,则会调用该回调。

反过来就没有这样的回调,但是如果使用该函数SecurityComponent::requireSecure设置,则它是一个仅限 https 的所有操作的数组。requireSecure()

所以你可以在你的 AppController 中做这样的事情:

public function beforeFilter(){
    // Check if current action is secure but shouldn't be
    if( 
        $this->request->is('ssl')
        &&
        !in_array($this->request->params['action'], $this->Security->requireSecure) 
    ){
        // Redirect to the http URL
        $this->redirect('http://' . env('SERVER_NAME') . $this->here);
    }
}
于 2012-07-09T11:42:41.890 回答