Page 1 of 1

Url of the current server

Posted: Mon Oct 11, 2004 4:13 pm
by Shendemiar
I like to make portable code, and some of my links need to be full url. How do i receive the url of the current server?

Posted: Mon Oct 11, 2004 4:24 pm
by John Cartwright
look at

Code: Select all

<?php

var_export($_SERVER);

?>

Posted: Mon Oct 11, 2004 11:43 pm
by timvw
something like?

Code: Select all

<?php

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

Posted: Tue Oct 12, 2004 12:25 pm
by Shendemiar
Yeah! That's exelent! Funny there are no premade function for that.

Posted: Tue Oct 12, 2004 12:42 pm
by mudkicker
thanx timvw this helped me too.