I have a function returning an array, called curPageURL. On my local apache, I accessed the return-value of the Page like this: $pageUrl = explode('?',curPageURL())[0];
it worked pretty fine. But on live it didn't work. It took me a lot of time to figure out, that the error was accessing the array.
This solved the issue:
$pageUrl = explode('?',curPageURL());
$pageURL = pageURL[0];
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_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;
}
Can anybody explain why?
Is it forbidden to access array index directly by function's return value? If so, Why did it worked at my localhost, but not at my live host?