title: Converting IPv6 to IPv4 address in PHP
body: <p>I need to convert IPv6 addresses to IPv4 addresses. To do this, I used code from <a href="https://stackoverflow.com/a/38665008/366904">pedmillon's answer to a related question</a>:</p>
  
  <pre><code>$ipv6 = $_SERVER['REMOTE_ADDR'];
  $ipv4 = hexdec(substr($ipv6, 0, 2)). "." . hexdec(substr($ipv6, 2, 2)). "." . hexdec(substr($ipv6, 5, 2)). "." . hexdec(substr($ipv6, 7, 2));
  </code></pre>
  
  <p>I tried it in my localhost and ::1 gets converted to 0.1.0.0. Is this code correctly working?</p>
  
  <p>I believe it should be showing 127.0.0.1 instead of 0.1.0.0.</p>