Code: Select all
how to get the full url string from a address bar of relative site ? not only the domain name.
Moderator: General Moderators
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"];
}