How can I get the full URL in PHP, not just part of it?

This question already has an answer here:

  • Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)? 12 answers
  • Get the full URL in PHP 28 answers

  • 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

    下一篇: 我如何在PHP中获得完整的URL,而不仅仅是它的一部分?