Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mgmilcher/1993874 to your computer and use it in GitHub Desktop.
Save mgmilcher/1993874 to your computer and use it in GitHub Desktop.
simple ssl_requirement in cakePHP
<?
class AppController extends Controller {
var $sslRequired = array('login', 'logout');
var $sslAllowed = array('index');
var $beforeFilter = array('ensureProperProtocol');
private function sslRequired() {
return in_array($this->action, $this->sslRequired);
}
private function sslAllowed() {
return in_array($this->action, $this->sslAllowed);
}
private function ensureProperProtocol () {
if ($this->sslAllowed())
return true;
if (!env('HTTPS') && $this->sslRequired()) {
$this->redirect('https://' . env('HTTP_HOST') . env('REQUEST_URI'));
}
elseif (env('HTTPS') && !$this->sslRequired()) {
$this->redirect('http://' . env('HTTP_HOST') . env('REQUEST_URI'));
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment