Welcome Guest, Not a member yet? Register   Sign In
.htaccess to force http using https and still get rid off index.php etc.
#4

[eluser]skunkbad[/eluser]
What kind of site needs SSL on every page? Why not use per controller or per method?

Code:
public function force_ssl()
{
        // force SSL if available
        if( USE_SSL != 0 && ! isset( $_SERVER['HTTPS'] ) )
        {
                $this->load->helper('string');
                header("Location: " . secure_base_url() . trim_slashes( $this->uri->uri_string() ) . url_suffix(), TRUE, 301);
                exit;
        }
}

If you extend CI_Controller with MY_Controller, and put that in MY_Controller, you simply call:

$this->force_ssl();

wherever you need it.

Keep in mind, in my code secure_base_url() is a special function that I put in MY_url_helper.php:

Code:
function secure_base_url()
{
        $CI = get_instance();
        $url = $CI->config->slash_item('base_url');
        if(USE_SSL === 1)
        {
                $url = substr($url, 0, 4).'s'.substr($url, 4);
        }
        return $url;
}

USE_SSL is a constant, which you could put in config/constants or wherever you feel is good.


Messages In This Thread
.htaccess to force http using https and still get rid off index.php etc. - by El Forum - 06-19-2011, 10:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB