Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to $_SERVER['REMOTE_ADDR'] in php

Tags:

php

ip-address

Is there any alternative to the $_SERVER['REMOTE_ADDR']. Which returns the ip address of the computer accessing a site. I'm trying to search about same external ip assigned by router, and got into this: How do two computers connect to same external address through NAT? And found out that the same external ip is assigned if the computers are connected to the same modem. I'm creating a simple login program in php which uses $_SERVER['REMOTE_ADDR'] to determine if a user is already logged in somewhere else in the same network. And this won't actually work if those computers are connected to the same modem through the router.

like image 299
Wern Ancheta Avatar asked Jan 30 '26 22:01

Wern Ancheta


1 Answers

No, this is the best you can do. The server only knows where the request is coming from, and that may be a proxy or a NAT router or some other entity which is not the direct enduser. There's nothing you can do about that, that's how networks work.

The solution is simple: Don't use IPs to identify users. Ever. Use cookies.

like image 134
deceze Avatar answered Feb 01 '26 14:02

deceze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!