Rate this script:  I Love it  /   I Hate it

Using PHP to find your current url


Author: WSE
Website: http://www.webscriptexpert.com

Usage

Pretty self explanatory

Code

<?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;
?>

<p><center>Free php provided by <a href=http://www.webscriptexpert.com>Web Script Expert </a></center></p>

 

 
Using PHP to find your current url scripts | Using PHP to find your current url snippet | Using PHP to find your current url example | Using PHP to find your current url tutorial | Using PHP to find your current url code