0

How do I find my real IP address?

If I do:-

$_SERVER['REMOTE_ADDR']

It gives me wrong IP Address (157.191.122.36), which I've checked as it gives me same values even when my site is accessed through different locations and countries.

This place somehow, gives me the right IP (64.74.66.230) at http://www.whatismyip.com/, but I can't get the same value through the above PHP code.

EDIT

I tried the URL mentioned in the comment. None of the solutions worked for me. It is clear now though that ehen using $_SERVER["REMOTE_ADDR"], I get the server's IP address rather than the visitor's.

halfer
  • 19,824
  • 17
  • 99
  • 186
Steve
  • 2,546
  • 8
  • 49
  • 94

1 Answers1

1

$_SERVER['REMOTE_ADDR'] is the only reliable IP address you'll get - it's extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you'll get the proxy's address, not the user's.

Any of the other header-based ones are unreliable, as HTTP headers are trivial to forge. You can use the information from them, if you'd like, as long as you don't TRUST it.

source: definitive way to get user ip address php

Community
  • 1
  • 1
  • But it definitely isn't reliable in my case and the other sites (i.e. whatsmyip.com) show me correct address ... How are they doing it ... – Steve Jun 25 '13 at 22:27
  • If they are using a transparent proxy, you wont ever be able to see their real ip....that's the point. – Hydra IO Jun 25 '13 at 22:38
  • Hi Hydra, Thank you for your comment. Could you assist further that how can I use this within my PHP based page? Thanks. – Steve Jun 25 '13 at 22:42
  • Talk to your hosting company and ask them about whether they have a proxy server in front of your webserver, and how you are supposed to get the clients IP address. You probably can use `$_SERVER['HTTP_X_FORWARDED_FOR']`, which is a comma separated list of IP addresses that went to a proxy to have the request forwarded (like in the browser goes to a proxy that goes to YOUR proxy that goes to your server - two proxies, two forwards, possibly two IP addresses, and you only want the one that YOUR proxy detected, not the myriad of 10.0.0.0/8 addresses of private networks.) – Sven Jun 25 '13 at 23:06
  • When I used `$_SERVER['HTTP_X_FORWARDED_FOR']`, I get `Undefined index: HTTP_X_FORWARDED_FOR in require_once()` ... Don't know if I could get the visitor's IP as I've tried almost evrything ... I don't know how these external services can get the correct IP ... – Steve Jun 25 '13 at 23:32