src/HTTP.php
public static function detectBaseURL(){

		if(PHP_SAPI == 'cli') return 'http://php-cli.invalid/';

		$protocol = 'http://';

		if(isset($_SERVER['HTTPS']) &&
			filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)){

			$protocol = 'https://';
		}

		/*
		 * We use Apache's user-dir feature for our local development
		 * environments (e.g. "http://localhost/~Academic/"). In order for
		 * base URL detection to properly pick up on these URL's we  use the
		 * CONTEXT_PREFIX environment variable provided by recent (2.3.13+)
		 * versions of Apache.
		 */

		if(isset($_SERVER['CONTEXT_PREFIX'])){

			$path = trim($_SERVER['CONTEXT_PREFIX'], '/\\') . '/';
		}
		else{

			$path = './';
		}

		return self::normaliseURL("{$protocol}{$_SERVER['HTTP_HOST']}/{$path}");
	}
public static function detectBaseURL(){

		if(PHP_SAPI == 'cli') return 'http://php-cli.invalid/';

		$protocol = 'http://';

		if(isset($_SERVER['HTTPS']) &&
			filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)){

			$protocol = 'https://';
		}

		/*
		 * We use Apache's user-dir feature for our local development
		 * environments (e.g. "http://localhost/~Academic/"). In order for
		 * base URL detection to properly pick up on these URL's we  use the
		 * CONTEXT_PREFIX environment variable provided by recent (2.3.13+)
		 * versions of Apache.
		 */

		if(isset($_SERVER['CONTEXT_PREFIX'])){

			$path = trim($_SERVER['CONTEXT_PREFIX'], '/\\') . '/';
		}
		else{

			$path = './';
		}

		return self::normaliseURL("{$protocol}{$_SERVER['HTTP_HOST']}/{$path}");
	}
public static function detectBaseURL ( ) { if ( PHP_SAPI == 'cli' ) return 'http://php-cli.invalid/' ; $ protocol = 'http://' ; if ( isset ( $ _SERVER [ 'HTTPS' ] ) && filter_var ( $ _SERVER [ 'HTTPS' ] , FILTER_VALIDATE_BOOLEAN ) ) { $ protocol = 'https://' ; } /*
		 * We use Apache's user-dir feature for our local development
		 * environments (e.g. "http://localhost/~Academic/"). In order for
		 * base URL detection to properly pick up on these URL's we  use the
		 * CONTEXT_PREFIX environment variable provided by recent (2.3.13+)
		 * versions of Apache.
		 */ if ( isset ( $ _SERVER [ 'CONTEXT_PREFIX' ] ) ) { $ path = trim ( $ _SERVER [ 'CONTEXT_PREFIX' ] , '/\\' ) . '/' ; } else { $ path = './' ; } return self :: normaliseURL ( "{$protocol}{$_SERVER['HTTP_HOST']}/{$path}" ) ; }
Detect the base URL for the current request.

<p>URL detection is based upon the server environment. It is assumed the
URL always points to a directory on the server, <strong>not</strong> a
file. A trailing slash is thus always appended to the URL returned.</p>

<p>When When the request is run in CLI-mode, the URL
<strong>http://php-cli.invalid/</strong> is returned.</p>

@return string
Detect the base URL for the current request .