Created
August 21, 2009 06:47
-
-
Save speedmax/171698 to your computer and use it in GitHub Desktop.
simple ssl_requirement in cakePHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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