Created
June 13, 2016 11:58
-
-
Save richjenks/d025f2bcc1caf21fb122206d05a503d9 to your computer and use it in GitHub Desktop.
Attempt at providing the current URL in the cleanest possible manner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function url() { | |
$url = @( $_SERVER['HTTPS'] != 'on' ) ? 'http://' : 'https://'; // Protocol | |
$url .= $_SERVER['SERVER_NAME']; // Host | |
if ($_SERVER['SERVER_PORT'] != 80) $url .= ':'.$_SERVER['SERVER_PORT']; // Port | |
if ($_SERVER['REQUEST_URI'] !== '/') $url .= $_SERVER['REQUEST_URI']; // Request | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment