Last active
January 6, 2016 06:25
-
-
Save cyonks/99c514155a6680c962d5 to your computer and use it in GitHub Desktop.
PHP获取当前浏览器访问的链接
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 | |
/** | |
* 获取当前浏览器访问的链接 | |
* @return String | |
*/ | |
function cur_url() { | |
if (isset($_SERVER['SERVER_PROTOCOL'])) { | |
$sch = strpos($_SERVER['SERVER_PROTOCOL'], 'https') !== false ? 'https://' : 'http://'; | |
} | |
else { | |
$sch = 'http://'; | |
} | |
if (strpos($_SERVER['HTTP_HOST'], ":") !== false) list($host, $port) = explode(":", $_SERVER['HTTP_HOST']); | |
else $host = $_SERVER['HTTP_HOST']; | |
$path = $_SERVER['REQUEST_URI']; | |
$url = $sch . $host . (isset($port) && !empty($port) ? ':' . $port : '') . $path; | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment