Created
October 21, 2011 20:19
-
-
Save rickharris/1304847 to your computer and use it in GitHub Desktop.
FuelPHP method-specific, controller-based SSL solution
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
<?php | |
class Controller extends Fuel\Core\Controller { | |
public $secure = array(); | |
public function before($data = null) | |
{ | |
$should_be_secure = in_array($this->request->action, $this->secure); | |
$is_secure = isset($_SERVER['HTTPS']); | |
if ($should_be_secure && ! $is_secure) | |
{ | |
$this->redirect_to_protocol('https'); | |
} | |
else if (! $should_be_secure && $is_secure) | |
{ | |
$this->redirect_to_protocol('http'); | |
} | |
parent::before(); | |
} | |
private function redirect_to_protocol($protocol = 'http') | |
{ | |
$url = $protocol . '://' . CCD_HOSTNAME . $_SERVER['REQUEST_URI']; | |
Response::redirect($url, 'location', 301); | |
die; | |
} | |
} |
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
<?php | |
class Controller_Example extends Controller_Template { | |
public $secure = array('index'); | |
public function action_index() | |
{ | |
// This method will be forced to 'https://' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment