Home > other >  Not getting correct IP address on the website
Not getting correct IP address on the website

Time:05-04

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/');

CodePudding user response:

$ip=$_SERVER['REMOTE_ADDR'];

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

CodePudding user response:

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?

  • Related