Tag Archives: force

CakePhp 2 Tip #11- Force SSL Connection

cake-logo

In your app Controller add;

class AppController extends AppController {

    public $components = array('Security');

    public function beforeFilter() {
        if (isset($this->params['admin'])) {
            $this->Security->blackHoleCallback = 'forceSSL';
            $this->Security->requireSecure();
        }
    }

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

More info:
http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html