phpipipv6ipv4

How can I get both IPv4 and IPv6 address using PHP code?


I have a script which sends a request to another server but problem is that IPv6 does not supported so if I send IPv6 then give error so i need this one of two:

  1. Get IPv4 address all time or
  2. Get both IPv4 and IPv6 addresses

I use this code to get the IP address

$ip = $_SERVER["REMOTE_ADDR"];

But this function only returns one IPv address. How can I get all time IPv4 or get both addresses?


Solution

  • You can't.

    Only the IP address the request came from is available.

    There's no reliable way to identify other IP addresses (my laptop currently has 12 IP addresses) that route to the same computer.