0

I am using cloudflare and I am trying to get a users IPV4 address.

I have tried using - $userip = $_SERVER['HTTP_CF_CONNECTING_IP'];

however it's giving an IPv6 IP,

I require a IPv4 address as an IP API i use, gives much more accurate information on IPv4.

Any ideas?

1 Answers1

0

There is no conversion from IPv6 (128-bit address) to Ipv4 (32-bit address).

$_SERVER["HTTP_CF_CONNECTING_IP"] is your visitor IP. If you receive an IPv6, then this visitor is using a network interface that supports an IPv6, and that cloudflare server is also supporting IPv6 to be able to communicate with these visitors.

You should support IPv6 in your applications too. for example

  • At the database, you store them in VARBINARY(16) instead of VARBINARY(4)
  • Using functions that support IPv6 like inet_ntop and inet_pton

Check this working-with-ipv6-addresses-in-php

Check this also disable IPv6 support in CloudFlare

Accountant م
  • 6,975
  • 3
  • 41
  • 61