This is odd, but for some reason the $_SERVER[\"SCRIPT_URI\"]
will not return the domain name when I am in child/sub-pages but will only work on the main page.
If your browser formats JSON
documents nicely and no output has taken place, inserting the following will result in something more readable than var_dump
:
header('Content-Type: application/json');die(json_encode($_SERVER));
phpinfo()
will also provide a list of all $_SERVER
values and so much more!
Late late reply. I use this piece of script to store information in my db. Hope this might help someone. How to get your full url and the ip address of the client access from.
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
$url = $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
echo $ip;
echo "<br>";
echo $url;
If you need domain name, use:
$_SERVER['HTTP_HOST']
var_dump($_SERVER)
and see what suites your needs.
P.S. Making use of unsanitized $_SERVER["PHP_SELF"]
could be a security risk.
On Apache, SCRIPT_URI only exists when mod_rewrite is enabled.
Apache requires:
rewrite_module (note: use platform specific load syntax)
and
RewriteEngine On
statements in the Apache configuration file at the appropriate locations.
Then restart Apache, and it should work fine.