Get entire url

espfutbol98

New Member
Messages
200
Reaction score
2
Points
0
I'm wondering how to retrieve the entire url in PHP because I use .htaccess url rewriting and also a lot of variables. This can be frustrating when you are redirected to a login page and once you are logged in, sent somewhere else.
 

zapzack

New Member
Messages
606
Reaction score
19
Points
0
Read the comments in the following php code:

PHP:
<?php
  // find out the domain:
  $domain = $_SERVER['HTTP_HOST'];
  // find out the path to the current file:
  $path = $_SERVER['SCRIPT_NAME'];
  // find out the QueryString:
  $queryString = $_SERVER['QUERY_STRING'];
  // put it all together:
  $url = "http://" . $domain . $path . "?" . $queryString;
  echo "The current URL is: " . $url . "<br />";
  
  // An alternative way is to use REQUEST_URI instead of both
  // SCRIPT_NAME and QUERY_STRING, if you don't need them seperate:
  $url2 = "http://" . $domain . $_SERVER['REQUEST_URI'];
  echo "The alternative way: " . $url2;
?>
 
Top