How can I get the full URL in PHP, not just part of it?
This question already has an answer here:
Use $_SERVER["SERVER_NAME"]
to get the host name wp.raddyx.in
Use $_SERVER["HTTPS"]
to check for http vs https.
You might need $_SERVER["SERVER_PORT"]
too and some other misc things that can appear in a URL (like PHP_AUTH_USER
)
You can not get the hash part of the URL ( #Fiona%20Brown
) since hashes are client-side only. They are not sent to the server.
Relevant manual page: http://php.net/manual/en/reserved.variables.server.php
使用$_SERVER[HTTP_HOST]
:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
链接地址: http://www.djcxy.com/p/42278.html
上一篇: 在PHP中获取当前页面的完整URL