Categories
Technology

Forcing SSL in Kohana

If you ever need to force certain controllers to use SSL in Kohana, it’s actually quite easy:

In Kohana’s controller class (/system/classes/controller.php) add a variable and before function like this:

public $require_ssl = FALSE;

	public function before()
	{
		parent::before();

		if ($this->force_ssl && Request::$protocol == 'http')
		{
			Request::Instance()->redirect(URL::site(Request::Instance()->uri, 'https'));
		}
	}

And then set “force_ssl” to be true at the top of each controller that you want SSL to be required for:

Class Controller_mycontrollername extends Controller_Template
{
     public $force_ssl = TRUE;

By darylchymko

Code Wrangler and ultrarunner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s