Skip to content

Uses the ( ip location api) to block certain countries of your choosing.

Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



47 Commits

Repository files navigation


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.


Uses the ( ip location api) to block certain countries of your choosing.






No releases published