Skip to content

Instantly share code, notes, and snippets.

@gmutschler
Created September 14, 2014 21:47
Show Gist options
  • Save gmutschler/a3135843dc44db13abb5 to your computer and use it in GitHub Desktop.
Save gmutschler/a3135843dc44db13abb5 to your computer and use it in GitHub Desktop.
Usefull for site located in subdirectories. Usage: put it in script located in the "home directory" of your site
<?php
function get_base() {
$scriptSubDir = str_replace(dirname(__FILE__), '', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
$baseURI = str_replace($scriptSubDir , '', str_replace('\\', '/',$_SERVER['SCRIPT_NAME']) );
$baseURI = preg_replace('/^\//', '', $baseURI);
$baseURI = preg_replace('/\/$/', '', $baseURI);
return $baseURI;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment