Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base_url returns wrong value when there is substring of server name in the url #80

Closed
am05mhz opened this issue Sep 29, 2013 · 1 comment

Comments

@am05mhz
Copy link

am05mhz commented Sep 29, 2013

base_url function returns wrong value when there is a substring of server name in the url. eg:

request_url: localhost/pico/local -> base_url = host/pico/ (pico installed in pico subfolder)
request_url: localhost/local -> base_url = host/
request_url: www.technology.com/tech -> base_url = www.nology.com/

solution:

private function base_url()
{
    global $config;
    if(isset($config['base_url']) && $config['base_url']) return $config['base_url'];

    $url = '';
    $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
    $script_url  = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
    if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/');

    $protocol = $this->get_protocol();
    return $protocol . '://' . rtrim(str_replace('/'.$url, '/', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
}
@PhrozenByte
Copy link
Collaborator

Fixed with #252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants