在PHP中获取当前页面的完整URL

时间:2014-08-21 11:02:10

标签: php url

如何在php中获取当前的完整URL?

实施例。完整网址:www.topclinique.ma/list-cliniques.php?t = cliniques& s = 0& c =卡萨布兰卡

2 个答案:

答案 0 :(得分:3)

您可以使用

$current_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

答案 1 :(得分:0)

试试这个:

if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||  isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}

$current_link = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $current_link;