title: PHP | Get private IP address from a client user?
body: <p>I know question but didn't find real answer on stackoverflow. This is not <code>X_FORWARDED_FOR</code>, <code>SERVER_NAME</code> or <code>SERVER_REMOTE_ADDR</code>, I want get local IP address of remote client connected to my server to detect who is really on local remote network is connected.</p>
  
  <p>Explain this:</p>
  
  <pre><code>ISP  &lt;----&gt;  ROUTER &lt;----&gt; LOCAL NETWORK &lt;----&gt; LOCAL PC
  </code></pre>
  
  <p>What I want to know?</p>
  
  <ol>
  <li>Public IP address of connected remote client <code>$_SERVER["REMOTE_ADDR"]</code>, okay, but!...</li>
  <li>Local IP address of connected client on public network (192.168.x.x, 10.x.x.x, 172.x.x.x)</li>
  </ol>
  
  <p>How to solve this problem? I have answer, so I think this should be know for everyone if want to know local IP address:</p>
  
  <p>You should use <code>CURL</code> and <code>curl_getinfo()</code> function. Then, point URL address anyone that you want (your main server ip or whatever), for example:</p>
  
  <pre><code>&lt;?php
      $ch = curl_init();
  
      $opt = curl_setopt($ch, CURLOPT_URL, "YOUR_SOME_URL_ADDRESS"); 
  
      curl_exec($ch);
  
      $response = curl_getinfo($ch);
  
      $result = array('client_public_address' =&gt; $response["primary_ip"],
                      'client_local_address' =&gt; $response["local_ip"]
              );
  
      var_dump($result);
  
      curl_close($ch);
  
  ?&gt;
  </code></pre>
  
  <p>Focus on <code>$response["primary_ip"]</code> which responses your Public address and <code>$response["local_ip"]</code> which reponses local address. Now this is example:</p>
  
  <pre><code>ISP  &lt;----&gt;  ROUTER &lt;----&gt; LOCAL NETWORK &lt;----&gt; LOCAL PC
   /\                                              /\
   ||                                              ||
   \/                                              \/
  $response["primary_ip"]                  &lt;----&gt; $response["local_ip"]
  213.x.x.x  (for example)                        192.168.1.3 (for example)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>array (size=2)
    'client_public_address' =&gt; string '213.xxx.xxx.xxx' (length=14)
    'client_local_address'  =&gt; string '192.168.1.3' (length=11)
  </code></pre>
  
  <p>This will NOT be giving a REAL local IP address! </p>
  
  <p>Thank you.</p>