It does not seem as simple. I use this popular function to get page full URL:
private function getBaseUrl() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
My PHP5 is on Windows server! That is why $_SERVER[“REQUEST_URI”] is empty. I used this workaround for Windows:
function fixRequestURI() {
if(!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
if($_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
}
However, it kinda works. My full URL is:
http://www.domain.com/web/en/contact/
Strangely, I get this as a result of my functions above:
http://www.domain.com/directory1/web/en/contact/index.php?go=3
This, so called, “directory1” is my physical directory to which domain.com is mapped. I understand the implications but… how would I get my full URL easily without any fixes, adjustments, etc. just like in JavaScript using document.location.href?
Thanks
Answering my question: this worked for me:
Please send me any thoughts if it can ever fail in any special circumstances.