What is the better way of getting the IP address in PHP:
getenv('REMOTE_ADDR');
or,
$_SERVER['REMOTE_ADDR'];
please tell me the difference, if any, between the two.
$_SERVER is a built in PHP variable, while getenv() ask the environment (probably Apache/IIS) for values.
The best way to get the IP is;
$ip = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : getenv('REMOTE_ADDR');
But I doubt there's any difference between these two variables... Hm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With