Archive for September, 2011

CakePHP Security component

Tuesday, September 6th, 2011

Lately I added CakePHP’s Security component to a controller. Using the example from the cakephp cookbook caused the $_POST array to be null. Turns out the Security component does not like hidden input fields and will null all the input fields you set validatePost = false.

My controller now looks like:

    var $components = array('Security');
    function beforeFilter() {
        parent::beforeFilter();
        $this->Security->blackHoleCallback = 'forceSSL';
        $this->Security->requireSecure('index', 'view');
        $this->Security->validatePost = false;
    }
 
    function forceSSL() {
        $protocol = 'https://';
        $this->redirect($protocol . env('SERVER_NAME') . $this->here);
    }