Skip to content

Instantly share code, notes, and snippets.

@GuiSevero
Created December 19, 2014 17:42
Show Gist options
  • Save GuiSevero/dd13acfe7a9d182ad9ee to your computer and use it in GitHub Desktop.
Save GuiSevero/dd13acfe7a9d182ad9ee to your computer and use it in GitHub Desktop.
PHP BaseUrl Function
<?php
function curPageURL()
{
preg_match('/index.php[\/]*(.*)/', ( ! empty($_SERVER['SUPHP_URI'])) ? $_SERVER['SUPHP_URI'] : $_SERVER['PHP_SELF'], $match);
$protocol = (isset($_SERVER['HTTPS'])) ? 's' : '';
$base_url = preg_split("/\?/", str_ireplace(((isset($match[1])) ? trim($match[1], '/') : ''), '', urldecode(trim((( ! empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '/'), '/'))));
$port = (isset($_SERVER['SERVER_PORT']) AND $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '';
$url = trim(sprintf("http".$protocol."://%s/%s", (( ! empty($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'localhost'.$port), reset($base_url)),'/') . '/';
return $url;
}
$baseHREF = curPageURL();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment