Not getting correct IP address on the website

I am using for getting IP of anybody who visits my website. (

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

$ip = file_get_contents('');

2 answers

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


    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