PHP Classes

PHP Cloudflare IP GEO: Get the IP of a user of a site that uses Cloudfare

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 133 All time: 9,305 This week: 206Up
Version License PHP version Categories
cfgeo 1.0.0GNU General Publi...5.6Networking, PHP 5, Geography


This class can get the IP of a user of a site that uses Cloudfare.

It takes the current user IP address from the HTTP headers that were sent to the server.

If the current site accesses are handled by Cloudflare, it checks specific headers set by Cloudflare servers that pass the current user computer IP address as well the two letter code of the country associated to that IP address.

The class can also return the name of the country associated to the current user country code.

Innovation Award
PHP Programming Innovation award nominee
June 2019
Number 10
Cloudflare is a popular proxy service that can help many sites to handle requests for their pages faster by serving those pages from servers spread around the world that cache the contents of the pages.

When a browser is used to access a site that is handled by Cloudflare, the actual site server does not see the IP address of the computer that runs the browser in the same way that happens when a site is not using Cloudflare to serve its pages.

The actual IP address that the user computer uses is passed to your site by Cloudflare using specific request variables.

This package can get the user IP address passed by Cloudflare, as well the country where the user is located.

Manuel Lemos
Picture of Meraj-Ul Islam
Name: Meraj-Ul Islam <contact>
Classes: 3 packages by
Country: Bangladesh Bangladesh
Age: 27
All time rank: 316443 in Bangladesh Bangladesh
Week rank: 276 Up6 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 1x


// require the class

// initialize the class
$cf = new cfGeo;

// get user's IP
echo 'IP: '.$cf->getClientIp().'<br>';

// get user's county code in ISO format
echo 'Country Code: '.$cf->getCountryCode().'<br>';

// get user's country name
echo 'Country Name: '.$cf->getCountryName().'<br>';

/* Your site need to be intergrated to cloudflare */


There are three functions available in this class. Call them individually along with the class. To get ip address from cloudflare, call: getClientIp() To get country code from cloudflare, call: getCountryCode() To get country from cloudflare, call: getCountryName()

  Files folder image Files  
File Role Description
Plain text file class.cfgeo.php Class The main class
Accessible without login Plain text file example.php Example Example usage of the class
Accessible without login Plain text file readme.txt Doc. The documentation file

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,305
This week:206Up