Skip to content
Uses the http://ipinfodb.com/ip_location_api.php (ipinfodb.com ip location api) to block certain countries of your choosing.
PHP
Branch: master
Clone or download
Matthew Gross Matthew Gross
Matthew Gross and Matthew Gross Update readme.txt
Latest commit 4fc5a76 Sep 14, 2014
Permalink
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
README.md Updating usage to reflect new changes. Sep 5, 2014

README.md

PHP-Country-Block

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

User must have an API Key from ipinfodb.com

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

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

##Usage

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!)

Example:

<?php

require_once "country-block.inc.php";

// 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 www.mattgross.net - This website is currently in development however.

You can’t perform that action at this time.