Skip to content

Instantly share code, notes, and snippets.

@cyonks
Last active January 6, 2016 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyonks/99c514155a6680c962d5 to your computer and use it in GitHub Desktop.
Save cyonks/99c514155a6680c962d5 to your computer and use it in GitHub Desktop.
PHP获取当前浏览器访问的链接
<?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