Home >Backend Development >PHP Tutorial >PHP gets the current domain name, host, URL, port, parameters, URL, path, proxy, etc.

PHP gets the current domain name, host, URL, port, parameters, URL, path, proxy, etc.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:43:45702browse
  1. //Get the domain name or host address
  2. echo $_SERVER['HTTP_HOST']."
    ";
  3. //Get the web page address
  4. echo $_SERVER['PHP_SELF'] ."
    ";
  5. //Get URL parameters
  6. echo $_SERVER["QUERY_STRING"]."
    ";
  7. //Get user agent
  8. echo $_SERVER['HTTP_REFERER'] ."
    ";
  9. //Get the complete url
  10. echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  11. echo 'http://' .$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
  12. //Full url including port number
  13. echo 'http://'.$_SERVER[ 'SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  14. //Only get the path
  15. $url='http://'.$_SERVER['SERVER_NAME']. $_SERVER["REQUEST_URI"];
  16. echo dirname($url);
  17. ?>
Copy code

php, URL


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn