Page 1 of 1

get url of a site

Posted: Sun Oct 25, 2009 8:52 am
by ranjitbd

Code: Select all

 
 
how to get the full url string from a address bar of relative site ? not only the domain name.
 
 

Re: get url of a site

Posted: Sun Oct 25, 2009 9:08 am
by markusn00b
How about this:

Code: Select all

echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Re: get url of a site

Posted: Sun Oct 25, 2009 2:19 pm
by requinix
It can get more complicated than that.

Code: Select all

function getURL() {
    $protocol = (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] == "off" ? "http" : "https");
    $server = (empty($_SERVER["HTTP_HOST"]) ? $_SERVER["SERVER_NAME"] : $_SERVER["HTTP_HOST"]);
    $port = ($_SERVER["SERVER_PORT"] == 80 && $protocol == "http" || $_SERVER["SERVER_PORT"] == 443 && $protocol == "https" ? "" : ":" . $_SERVER["SERVER_PORT"]);
    return $protocol . "://" . $server . $port . $_SERVER["REQUEST_URI"];
}