0

currently I am trying to store my clients IP address on view, this proving to be more complicated then expected.

Here is the code I am currently using.

<?php
    $ip = $_SERVER['REMOTE_ADDR'];
    print $_SERVER['REMOTE_ADDR'];
    $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
    $location = $details->country;
    print '<br>';
    print $details->country;
    print '<br>';
    print $details->city;
?>

which returns something that looks like this.

173.245.56.104
US
San Francisco

This IP and this location links back to a cloudflare server and not my actual IP address.

You can see that information here cf-173-245-56-104.cloudflare.com.

How ever when my buddies visit the same url which contains the document that is suppose to be giving the IP it gives them a different IP also connected to CloudFlare.

Example 1 being the following.

199.27.128.244
SG
Singapore

Which links to this cloudflare hostname cf-199-27-128-244.cloudflare.com.

And with a simple lookup you can see that it does not even provided the right GEO so for the reason I am looking to use this code, it would not even be viable if it's saying US based users are from Singapore or other countries.

enter image description here

So the question is, HOW can I get the REAL client IP address on visit?

Ritzy
  • 379
  • 1
  • 10

0 Answers0