speedmax (owner)

Revisions

gist: 171698 Download_button fork
public
Description:
simple ssl_requirement in cakePHP
Public Clone URL: git://gist.github.com/171698.git
Embed All Files: show embed
simple ssl_requirement in cakePHP.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?
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'));
    }
  }
}
?>