PHP gets the complete URL implementation code for the current page

  • 2020-06-12 08:43:35
  • OfStack

javascript implementation:

top.location.href    The address of the top-level window  this.location.href   The address of the current window 

PHP implementation:

# Test site :     http://localhost/blog/testurl.php?id=5
// Gets a domain name or host address  echo $_SERVER['HTTP_HOST']."<br>"; #localhost
// Get web page address  echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php
// Get url parameters  echo $_SERVER["QUERY_STRING"]."<br>"; #id=5
// Get the user agent  echo $_SERVER['HTTP_REFERER']."<br>"; 
// Get complete urlecho 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; #http://localhost/blog/testurl.php?id=5
// Contains the complete port number urlecho 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];  #http://localhost:80/blog/testurl.php?id=5
// Just take a path $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];  echo dirname($url); #http://localhost/blog


Related articles: