获取当前页面的完整 URL (PHP)
我正在处理这个页面:http://localhost/projectname/custom.php
<?php echo $_SERVER['REQUEST_URI'];?>
和 不要提供完整的位置.我应该用什么来获取完整的 url 位置?
Both <?php echo $_SERVER['REQUEST_URI']; ?>
and <?php echo $PHP_SELF; ?>
don't give full location. What should I use to grab the full url location?
推荐答案
function selfURL()
{
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
相关文章