$_SERVER['REMOTE_ADDR'] is giving ipv6-addresses

I have a PHP application to get the users details we check for the REMOTE_ADDR.
I used to check the $_SERVER[‘REMOTE_ADDR’] for the ipv4 content, but since the use of Cloudflare this variable is mostly empty.
I added a workaround so I replace the content of this variable with the cloudflares content from HTTP_CF_CONNECTING_IP

if (isset($_SERVER[“HTTP_CF_CONNECTING_IP”])) {
$_SERVER[‘REMOTE_ADDR’] = $_SERVER[“HTTP_CF_CONNECTING_IP”];
}

It does the job, but is there a reason why i only can see ipv6 and no longer the ipv4 of every user?
I have the dea that a can be tracked a longer time on a ipv4. Ipv6 is changing more often.

Welcome to the community! Have you tried to temporarily delete the AAAA record of the domain in which you have to use that PHP function? After that, wait a few minutes and try again. Hope it helps!

IPv6 is preferred by operating systems at multiple levels so that if a user has an IPv6 address and a target website supports IPv6 they will connect over it instead of IPv4.

4 Likes

fair enough, but the day before the start of Cloudflare we only got the ipv4 (and never 6)
Since the start most of the people are being identified as a 6.

I don’t completely understand why would you like to get only the user’s IPv4 address instead of IPv6.

Supporting both gives higher compatibility to all users, and due to the lack of available IPv4 addresses, IPv6 is slowly replacing the former protocol.

If your intention is to track the users visiting your website, there are better options available that analyzing IP addresses, since IPs in both protocols are extremely ephemeral.

Hope it helps!

Because Cloudflare advertises an IPv6 address for your website when proxied and now users with IPv6 address use and prefer it.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.