I am using Php superglobal $_SERVER['REMOTE_ADDR']
to get the client ip . But it always gives me different ip address and also ip provided by $_SERVER['REMOTE_ADDR']
is not correct my ip on local machine starts with 192.168. ... and so on but it gives me ip like 165.123. ... and when i open the page with different browsers it produces different results .
Asked
Active
Viewed 1,370 times
-1

pankaj roy
- 83
- 1
- 1
- 8
-
may be it is an external ipaddress which it is storing – suresh Aug 03 '18 at 05:33
-
What do you mean by external ip address – pankaj roy Aug 03 '18 at 05:34
-
The IP you are seeing, is the IP of the firewall of your company. – suresh Aug 03 '18 at 05:35
-
@Shanukk i am not using any proxy but still i get wrong ip and differebt ip everytime . – pankaj roy Aug 03 '18 at 05:40
1 Answers
1
The IP on your local machine is a private IP assigned by your router. A remote server gets the public IP of the WAN interface of the router. If the IP is changing, your ISP must be assigning your IP dynamically each time you connect.
Another possibility is that your ISP relays your web traffic through proxy servers. Then $_SERVER['REMOTE_ADDR']
is the IP of the proxy. If the IP changes each time, they have multiple proxies that they load balance.

Barmar
- 741,623
- 53
- 500
- 612
-
1isn't there any way to get the same ip consistently ? i looked at api of ipify.org and when i use their api it give a consistent ip – pankaj roy Aug 03 '18 at 05:39
-
It depends on the ISP whether they give you a consistent IP every time. I'm not sure what ipify.org is doing differently, maybe there's some caching. – Barmar Aug 03 '18 at 05:44
-
i am trying to fix session hijacking by storing IP address of a user. But each time i run this $_SERVER['REMOTE_ADDR'] it gives me different IP so thus my fix always fails. So how to manage getting a correct address of remote machine that is calling the URL? – Madhavarao Kulkarni Dec 15 '20 at 11:04
-
@MadhavaraoKulkarni You can't do it using IP address, and shouldn't try. – Barmar Dec 15 '20 at 16:26