Skip to content

Instantly share code, notes, and snippets.

@rickharris
Created October 21, 2011 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rickharris/1304847 to your computer and use it in GitHub Desktop.
Save rickharris/1304847 to your computer and use it in GitHub Desktop.
FuelPHP method-specific, controller-based SSL solution
<?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;
}
}
<?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