IP2Location Redirection

Hi,

Good day!

We are using IP2Location Redirection plugin. However, after adding our website to Cloudflare, we encountered a major issue.

The IP address as being in the US, but it was sent to the UK site.

A number of leads have defaulted to the UK - that should never happen unless the lead is from the UK, the default is “Int” for international if the IP location is undetermined or if it is not in AU, US or UK.

Can someone help me with this?
Thanks :slight_smile:

Probably the plugin is seeing Cloudflare IPs after you proxy your website.

The real client IP address is included in the “cf-connecting-ip” request header, not sure whether this plugin can pick up the header value or not.

Hi,

Thanks for you response :slight_smile:
But I’m not sure I understand it. Can you please explain it more?

if( array_key_exists( 'HTTP_CF_CONNECTING_IP', $_SERVER ) ) { 
	$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; 
}

Add this in wp-config.php before a famous comment line

/* That's all, stop editing! Happy publishing. */

What this does?

In $_SERVER array, it check if HTTP_CF_CONNECTING_IP exist

When TRUE (Of course, it would be because you’re using Cloudflare), it override the value of REMOTE_ADDR to HTTP_CF_CONNECTING_IP header which is actual IP to anyone interacting with Cloudflare server.

Why this work? Internally WordPres uses REMOTE_ADDR

Ref: https://github.com/WordPress/WordPress/search?q=REMOTE_ADDR

Alternatively, Install Cloudflare plugin. It will do as well.

1 Like

Thanks! I will try this one :slight_smile:

Hi,

I added this code to wp config but the issue still occurs.

It always goes to “Int” site, whereas for me it should be going to “AU” pages.
I also tested it through a VPN to the US but it still showed be the “Int” pages, not US pages.

I tried to disabled the IP Geolocation. I hope it works.

Should I need to delete also the code I added on wp config?

You can. Regarding that plugin, you can check with its author.

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