Hello guys,
I have a problem:
I use a function to give back values of $_SERVER[] or
$HTTP_SERVER_VARS[]
<php
function MiUrl() {
$protocol = (isset($HTTP_SERVER_VARS["HTTPS"]) &&
$HTTP_SERVER_VARS["HTTPS"] == "on") ? "https://" : "http://";
$url_prefix = "$protocol$HTTP_SERVER_VARS[HTTP_HOST]";
i
f (isset($HTTP_SERVER_VARS['REQUEST_URI'])) {
$valor = $HTTP_SERVER_VARS['REQUEST_URI'];
} elseif ($HTTP_SERVER_VARS['PATH_INFO']) {
$valor = $HTTP_SERVER_VARS['PATH_INFO'];
} elseif ($HTTP_SERVER_VARS['PHP_SELF']) {
$valor = $HTTP_SERVER_VARS['PHP_SELF'];
}
if ($commapos = strpos($valor, '?')) {
$valor = substr($valor, 0, $commapos);
}
return $url_prefix . $valor;
}
$Url_final = MiUrl();
echo "Resultado =" . $Url_final;
?>
One of the servers has PHP version 4.3.3 in which the code works perfectly.
The other has PHP version 4.0.6 and the code does not work. Nevertheless if I locate all code outside the function, returns perfectly. That is:
<?php
$protocol = (isset($HTTP_SERVER_VARS["HTTPS"]) &&
$HTTP_SERVER_VARS["HTTPS"] == "on") ? "https://" : "http://";
$url_prefix = "$protocol$HTTP_SERVER_VARS[HTTP_HOST]";
if (isset($HTTP_SERVER_VARS['REQUEST_URI'])) {
$val = $HTTP_SERVER_VARS['REQUEST_URI'];
} elseif ($HTTP_SERVER_VARS['PATH_INFO']) {
$val = $HTTP_SERVER_VARS['PATH_INFO'];
} elseif ($HTTP_SERVER_VARS['PHP_SELF']) {
$val = $HTTP_SERVER_VARS['PHP_SELF'];
}
if ($commapos = strpos($val, '?')) {
$val = substr($val, 0, $commapos);
}
echo "Result =" . $url_prefix . $val;
?>
However, the solution is not to leave it outside the function because this code is part of a bookstore from which different pages obtain their corresponding value.
The question is: Somebody knows if this situation has to do with the difference of versions PHP or some variable I specify of PHP that there is to set in php.ini?
Thousand thanks and I hope somebody can help me