Created
August 17, 2017 03:13
-
-
Save shierw/688e76a22475888b0d5af0f594b62b51 to your computer and use it in GitHub Desktop.
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
/** | |
* 获取当前 url | |
* @param $use_forwarded_host | |
* @return string | |
*/ | |
function getCurrentUrl($use_forwarded_host = false) { | |
$s = $_SERVER; | |
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on'); | |
$sp = strtolower($s['SERVER_PROTOCOL']); | |
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : ''); | |
$port = $s['SERVER_PORT']; | |
$port = ((! $ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port; | |
$host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null); | |
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port; | |
$urlOrigin = $protocol . '://' . $host; | |
return $urlOrigin.$s['REQUEST_URI']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment