-4

I have self written CMS which does not return correct user's IP address with the following:

define("USER_IP", $_SERVER['HTTP_X_FORWARDED_FOR']); 

It gives me the following notice:

Notice: Undefined index: HTTP_X_FORWARDED_FOR in /var/www/p00000/data/www/domain.ru/core/maincore.php on line 30

and line 20 = to the line define("USER_IP"...

A few question:

  • What should I do to get rid of this notice message?
  • How can I properly get user's IP address?

Thank you for your help!

  • 2
    HTTP_X_FORWARDED_FOR are usually just set by proxies. So if the user is not using a proxy HTTP_X_FORWARDED_FOR will not be set. And that error you get is that it isn't set – WizKid May 21 '14 at 16:52

1 Answers1

0
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
   define("USER_IP", $_SERVER['HTTP_X_FORWARDED_FOR']); 
} else {
  define("USER_IP", $_SERVER['REMOTE_ADDR']); 
 ...
Lal
  • 14,726
  • 4
  • 45
  • 70
cs45977
  • 400
  • 3
  • 11