Welcome Guest, Not a member yet? Register   Sign In
current_url() and HTTPS?
#1

[eluser]jeffpeck[/eluser]
Is there a reason that current_url() returns an URL starting with "http://", even when the current url actually starts with "https://"?
#2

[eluser]TheFuzzy0ne[/eluser]
Yes. Current URL pretty much returns the following:

The URL of your site as written for base_url in your config.php
the index.php page (often set to '' to hide it).
The URI as it is in your address bar.

I think you just need to override the function so that it actually returns the current URL (which can be spoofed), or at least changes the http:// to https:// when it should.

EDIT: I've probably got the numbers wrong in the calls to substr, but this code might do it.

./system/application/helpers/MY_url_helper.php
Code:
function current_url()
{
    $CI =& get_instance();
    $url = $CI->config->site_url($CI->uri->uri_string());
    if ($_SERVER['SERVER_PORT'] == 443)
    {
        $url = substr($url, 0, 4).'s'.substr($url, 4);
    }
    return $url;
}
#3

[eluser]jeffpeck[/eluser]
I used $_SERVER['HTTPS'], and your substr parameters were correct. Thanks.

Code:
function current_url()
    {
        $CI =& get_instance();
        $url = $CI->config->site_url($CI->uri->uri_string());
        
        if ($_SERVER['HTTPS'] == 'on')
            $url = substr($url, 0, 4).'s'.substr($url, 4);
            
        return $url;
    }




Theme © iAndrew 2016 - Forum software by © MyBB