Force SSL redirection in cakephp

SSL with cakephp

Step 1. use Security component.

 public $components = array('Security');

Step 2. use the below code to post data.

//Use the below code in parent controller's beforeFilter action
$this->Security->validatePost=false;
$this->Security->unlockedActions = array('action_1','action_2'); // unlock actions which you want to call in ajax without ssl 
$this->Security->blackHoleCallback = 'forceSSL'; //call forceSSL action to redirect http:// uri to https:// 
$this->Security->requireSecure();

// Defination of forceSSL function 
public function forceSSL() {
		if(json_decode($_SERVER['HTTP_CF_VISITOR'])->scheme=="http"){
			return $this->redirect('https://' . env('SERVER_NAME') . $this->here);
		}

	}