Page 1 of 1

Gettting the current url

Posted: Tue Feb 01, 2005 2:44 pm
by tores
How can I fetch the url witch is the address to the script currently running?

regards tores

Posted: Tue Feb 01, 2005 2:46 pm
by timvw
this is the function i found here (or somewhere else)

Code: Select all

function geturl()
{
  $ports = array('https' => 443, 'http' => 80);
  $prefix = empty($_SERVER['HTTPS']) ? 'http' : 'https';
  $url = $prefix;
  $url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
  $url .= '://';
  $url .= $_SERVER['HTTP_HOST'];
  $url .= $_SERVER['REQUEST_URI'];
  return $url;
}

echo geturl();