Skip to content
Uses the ( ip location api) to block certain countries of your choosing.
Branch: master
Clone or download
Matthew Gross Matthew Gross
Matthew Gross and Matthew Gross Update readme.txt
Latest commit 4fc5a76 Sep 14, 2014
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Update readme.txt Sep 14, 2014
src Create readme.txt Sep 14, 2014 Updating usage to reflect new changes. Sep 5, 2014


Uses the IP Location API to block certain countries of your choosing.

User must have an API Key from

Utilizes the PHP wrapper IP-User-Location for interactions.

##Links License for IP-User-Location
License for PHP-Country-Block


To download Click Here and unzip the file, and paste all files within the dist directory, in the directory of your choosing.

In order to utilize this class. Simply create an array of 2-letter country codes, and pass the array to the class with your IPInfoDB API Key and a path to the IPInfoDB Library (Optional: Only if changed!)



require_once "";

// Block Canada, United States, and Congo
$countries = array("CA","US","CG");

// Api Key
$api_key = "INSERT-API-KEY-HERE";

// path optional
// $path = "/extras/inc/";
// pass to class as third paramater if required.

// return true if someone has been blocked. false if not
$countryBlock = new countryBlock($countries, $api_key);

if($countryBlock->isBlocked === true) { // returned true
  // do whatever
  // you can redirect them to a "You are blocked" page, or simply provide a access denied page.
else {
  // do whatever
  // the user is free to use your website...


You could essentially put that code into a sort-of-like check.php page, make it the directory index, and then sent all unblocked requests to the index page. It's completely up to you.

See the examples directory for more examples.

Now for the ban hammer...

Thanks for viewing this github repo. This script has been tested.

If you, or one of your felow webmasters need a web developer for contract work, please reference my website at - This website is currently in development however.

You can’t perform that action at this time.