URL 方案和主机名部分必须从请求 URI 单独处理:
// in your example, this results in "http://"
$scheme = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] <> 'off') ? 'https://' : 'http://';
// in your example, this results in "mysite.com"
$hostname = $_SERVER['SERVER_NAME'];
// in your example, this results in "/browse/department/"
$uri = $_SERVER['REQUEST_URI'];
把碎片放在一起:
// in your example, this results in "http://mysite.com/browse/department/"
echo $scheme . $hostname . $uri;
阅读有关$_SERVER[]
数组内各种值的更多信息,或仅输出phpinfo()
以轻松搜索$_SERVER[]
数组以获取所需的值。