CloudFlare & CloudFront API class library

IP Geo Block has been developed separately from IP Geo API, a geolocation API class library which supports local database provided by only Maxmind and IP2Location.

But when you use CloudFlare or CloudFront as a reverse proxy service, you can retrieve a visitor’s IP address and country code from their special offered environment variables.

In this article, I’ll show you how to make use of their services.

CloudFlare

CloudFlare provides the verious client information via HTTP request headers. For example, an IP address can be retrieved from CF-Connecting-IP and the country code from CF-IPCountry.

So here is a sample of API class library for CloudFlare.

The key point here is that the above library should be named as class-zcloudflare.php and typically placed under the directory named /wp-content/ip-geo-api/zcloudflare/.

You might wonder why z + cloudflare?

Well, it’s just a matter of convenience for this plugin to give it a highest priority!

CloudFront

CloudFront also provides the client information via HTTP response headers. So the code is almost same as CloudFlare. You can find it at tokkonopapa/class-zcloudfront.php.

Pros and Cons

The advantage of using these libraries is definitely the response time that is important especially for front-end. It’s almost zero.

Response time of each API

On the other hand, the disadvantage is any IP address can not be retrieved on “Search” tab. In this case, you should just select other API emoji .

Search tab