This file contains 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 | |
/** | |
* @see: https://www.phpfreelancer.org/blog/php-get-current-url.php | |
*/ | |
function get_current_url() | |
{ | |
$url = false; | |
// check whether this script is being run as a web page | |
if (isset($_SERVER['SERVER_ADDR'])) | |
{ | |
$is_https = isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']; | |
$protocol = 'http' . ($is_https ? 's' : ''); | |
$host = isset($_SERVER['HTTP_HOST']) | |
? $_SERVER['HTTP_HOST'] | |
: $_SERVER['SERVER_ADDR']; | |
$port = $_SERVER['SERVER_PORT']; | |
$path_query = $_SERVER['REQUEST_URI']; | |
$url = sprintf('%s://%s%s%s', | |
$protocol, | |
$host, | |
$is_https | |
? (443 != $port ? ':' . $port : '') | |
: ( 80 != $port ? ':' . $port : ''), | |
$path_query | |
); | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment