Skip to content

Instantly share code, notes, and snippets.

@nawawi
Last active November 12, 2019 02:16
Show Gist options
  • Select an option

  • Save nawawi/1d0c9914f5cfd1ae8511db1ede2b96c9 to your computer and use it in GitHub Desktop.

Select an option

Save nawawi/1d0c9914f5cfd1ae8511db1ede2b96c9 to your computer and use it in GitHub Desktop.
<?php
function _basehost() {
if ( !empty($_SERVER["HTTP_HOST"]) ) {
$schema = ( !empty($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") ? "https://": "http://";
$host = $_SERVER["HTTP_HOST"];
return $schema.$host;
}
return null;
}
function _baseurl() {
if ( !empty($_SERVER['SCRIPT_NAME']) ) {
$base = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/")+1);
if ( $base != '/') $base = rtrim($base,'/');
$host = _basehost();
$base = ( !empty($host) ? ( ( $base != '/' ) ? $host.$base : $host."/".$base ) : ( ( $base != '/' ) ? $base : "" ) );
return rtrim($base,'/');
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment