title: How can I get both IPv4 and IPv6 address using PHP code?
body: <p>I have a script which sends a request to another server but problem is that <code>IPv6</code> does not supported so if I send <code>IPv6</code> then give error so i need this one of two:</p>
  
  <ol>
  <li>Get <code>IPv4</code> address all time 
  or</li>
  <li>Get both <code>IPv4</code> and <code>IPv6</code> addresses</li>
  </ol>
  
  <p>I use this code to get the <code>IP</code> address</p>
  
  <pre><code>function getRealIP()
      {
          if (isset($_SERVER["HTTP_CLIENT_IP"])) {
              $ip = $_SERVER["HTTP_CLIENT_IP"];
          } elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
              $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
          } elseif (isset($_SERVER["HTTP_X_FORWARDED"])) {
              $ip = $_SERVER["HTTP_X_FORWARDED"];
          } elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
              $ip = $_SERVER["HTTP_FORWARDED_FOR"];
          } elseif (isset($_SERVER["HTTP_FORWARDED"])) {
              $ip = $_SERVER["HTTP_FORWARDED"];
          } else {
              $ip = $_SERVER["REMOTE_ADDR"];
          }
  
          // Strip any secondary IP etc from the IP address
          if (strpos($ip, ',') &gt; 0) {
              $ip = substr($ip, 0, strpos($ip, ','));
          }
          return $ip;
      }
  </code></pre>
  
  <p>But this function only returns one <code>IPv</code> address. How can I get all time <code>IPv4</code> or get both addresses?</p>