title: PHP: real IP address with API
body: <p>Hello i use this api: <a href="http://ipapi.co/json" rel="nofollow noreferrer">http://ipapi.co/json</a> to get country, city and real ip address in localhost (127.0.0.1) work perfect, but when i put my code to my website my code not show address of the client, but address of the server how can i fix this ?</p>
  
  <p>I can get client ip address with <code>$_SERVER['REMOTE_ADDR'];</code> but i need this api to get country and city with: <a href="http://ipapi.co/json" rel="nofollow noreferrer">http://ipapi.co/json</a>.</p>
  
  <pre><code>Function TTT() {
      $ip = false;
      $city = false;
      $region = false;
      $country = false;
      $country_code = false;
  
      if($json = @file_get_contents("http://www.geoplugin.net/json.gp")) {
        $obj = json_decode($json);
        if(isset($obj-&gt;geoplugin_request) &amp;&amp; $obj-&gt;geoplugin_request != false) {
          $ip = "IP: ". $obj-&gt;geoplugin_request. "&lt;/br&gt;";
        }
        if(isset($obj-&gt;geoplugin_city) &amp;&amp; $obj-&gt;geoplugin_city != false) {
          $city = "City: ". $obj-&gt;geoplugin_city. "&lt;/br&gt;";
        }
        if(isset($obj-&gt;geoplugin_city) &amp;&amp; $obj-&gt;geoplugin_city != false) {
          $region = "Region: ". $obj-&gt;geoplugin_city. "&lt;/br&gt;";
        }
        if(isset($obj-&gt;geoplugin_countryName) &amp;&amp; $obj-&gt;geoplugin_countryName != false) {
          $country = "Country: ". $obj-&gt;geoplugin_countryName. "&lt;/br&gt;";
        }
        if(isset($obj-&gt;geoplugin_countryCode) &amp;&amp; $obj-&gt;geoplugin_countryCode != false) {
          $country_code = "Country Code: ". $obj-&gt;geoplugin_countryCode. "&lt;/br&gt;";
        }
  
        return $ip. $city. $region. $country. $country_code;
      }
  }
  
  echo TTT();
  </code></pre>