get url of a site
Posted: Sun Oct 25, 2009 8:52 am
Code: Select all
how to get the full url string from a address bar of relative site ? not only the domain name.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
how to get the full url string from a address bar of relative site ? not only the domain name.
Code: Select all
echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];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"];
}