Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Created April 12, 2014 09:19
Show Gist options
  • Select an option

  • Save ruliarmando/10526448 to your computer and use it in GitHub Desktop.

Select an option

Save ruliarmando/10526448 to your computer and use it in GitHub Desktop.
get site base url
function base_url()
{
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, 5)) == 'https' ? 'https://' : 'http://';
$path = $_SERVER['PHP_SELF'];
$path_parts = pathinfo($path);
$directory = $path_parts['dirname'];
$directory = ($directory == "/") ? "" : $directory;
$host = $_SERVER['HTTP_HOST'];
return $protocol . $host . $directory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment