简体   繁体   中英

Not getting correct IP address on the website

I am using https://ident.me/ for getting IP of anybody who visits my website. ( https://notablee.co/get_ip )

But i am only getting the Shared Hosting IP (50.87.141.159) instead of the Visitors IP Address.

$ip = file_get_contents('https://ident.me/');
$ip=$_SERVER['REMOTE_ADDR'];

Fixed this. Thanks to 'Professor Abronsius' for a quick fix.

While your answer is not entirely wrong, you should consider that your code sits behind a loadbalancer or proxy. In this case, the $_SERVER array should contain the field X_HTTP_FORWARDED_FOR which contains a list of all previous IP addresses as a comma-separated string.

Also read this SO article How to use HTTP_X_FORWARDED_FOR properly?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM