Forum Moderators: coopster
<?php
$address = getenv("REMOTE_ADDR");
echo "Your IP address is $address.";
?>
But only this will work:
<?php
$address = $_SERVER['REMOTE_ADDR'];
echo "Your IP address is $address.";
?>
--> wrapping getenv() around the latter fails too.
So, should I be using getenv()?
Why doesn't it produce the users IP address in this case?
php.net mentions this form:
if (getenv(HTTP_X_FORWARDED_FOR)){
$ip=getenv(HTTP_X_FORWARDED_FOR);
}
else {
$ip=getenv(REMOTE_ADDR);
}
Thanks for any clarity-
<?php
$address = getenv('REMOTE_ADDR');
echo "Your IP address is $address.";
?>
>> Your IP address is .
-------------------------------------------------
Using:
<?php
$address = $_SERVER['HTTP_USER_AGENT'];
echo "Your IP address is $address.";
?>
OR...
<?php
$address = $_SERVER['REMOTE_ADDR'];
echo "Your IP address is $address.";
?>
Work correctly- so are they wrong to use? Is getenv() necessary? I'm using PHP 4.2.2- just a bit confusing when your trying to learn.
Thanks-