Skip to content

Instantly share code, notes, and snippets.

@isu3ru
Created September 7, 2017 10:46
Show Gist options
  • Save isu3ru/2c53f52f26ac09a030bc1f7f52d566d3 to your computer and use it in GitHub Desktop.
Save isu3ru/2c53f52f26ac09a030bc1f7f52d566d3 to your computer and use it in GitHub Desktop.
<?php
function base_url() {
$isSecure = false;
if (isset($_SERVER['HTTPS'])) {
$isSecure = $_SERVER['HTTPS'] == 'on';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';
return sprintf("%s://%s", $REQUEST_PROTOCOL, $_SERVER['HTTP_HOST']);
}
// echo base_url();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment