Welcome Guest, Not a member yet? Register   Sign In
Questions about CI + SSL
#1

[eluser]DeaD SouL[/eluser]
Hello coders Wink

I use
Code:
anchor()
function to generate the href links

1) Is there any similar function to generate https links? Or I should create my own?


2) How can I use SSL for certain controllers ?

This is my first time to use SSL,
So, please don't skimp about any security tips or anything else.

Please help me out.. I'm stuck in this Sad

Thanks a lot in advance Smile
#2

[eluser]Phil Sturgeon[/eluser]
This is the best solution I have come accross, using routes to define secure pages.

Other solutions exist (in their hundreds) on Google.
#3

[eluser]DeaD SouL[/eluser]
Thanks Phil Sturgeon, I'll check that link
#4

[eluser]richfearless[/eluser]
This is not my own solution, but i find this quite helpful if you have used <?=base_url()?> to get the location for href's:
Code:
$config['base_url']    = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . '/site/';

Again, this is not my own solution.
#5

[eluser]DeaD SouL[/eluser]
Thanks richfearless,

Actually, I made this function
Code:
function anchor_ssl($segments='', $text=NULL, $attributes='')
{
    $return = anchor( $segments, $text, $attributes );
    return str_replace( 'href="http://', 'href="https://', $return );
}

it did the job, but it keeps calling str_replace() with each time anchor_ssl() is being called

so, i created ssl_url_helper.php, based on url_helper.php
Code:
if ( ! function_exists('site_url_ssl'))
{
    function site_url_ssl($uri = '')
    {
        $CI =& get_instance();
        if (is_array($uri))
        {
            $uri = implode('/', $uri);
        }

        if ($uri == '')
        {
            return $CI->config->slash_item('base_ssl_url').$CI->config->item('index_page');
        }
        else
        {
            $suffix = ($CI->config->item('url_suffix') == FALSE) ? '' : $CI->config->item('url_suffix');
            return $CI->config->slash_item('base_ssl_url').$CI->config->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
        }
//        return $CI->config->site_url($uri);
    }
}

// ------------------------------------------------------------------------

if ( ! function_exists('anchor_ssl'))
{
    function anchor_ssl($uri = '', $title = '', $attributes = '')
    {
        $title = (string) $title;

        if ( ! is_array($uri))
        {
            $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url_ssl($uri) : $uri;
        }
        else
        {
            $site_url = site_url_ssl($uri);
        }

        if ($title == '')
        {
            $title = $site_url;
        }

        if ($attributes != '')
        {
            $attributes = _parse_attributes($attributes);
        }

        return '<a href="'.$site_url.'">'.$title.'</a>';
    }
}

and added this in config.php
Code:
$config['base_url']    = "http://domain.ext/folder";
$config['base_ssl_url']    = str_replace('http://', 'https://', $config['base_url']);

so, instead of using anchor('url', 'title', 'attributes'), i use anchor_ssl('url', 'title', 'attributes') to generate the https links




Theme © iAndrew 2016 - Forum software by © MyBB