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

2 answers

  • answered 2022-05-04 10:50 Usman Malik

    $ip=$_SERVER['REMOTE_ADDR'];
    

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

  • answered 2022-05-04 11:03 Honk der Hase

    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?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum