Skip to content

Instantly share code, notes, and snippets.

@k0nsl
Last active December 17, 2015 08:29
Show Gist options
  • Save k0nsl/5580365 to your computer and use it in GitHub Desktop.
Save k0nsl/5580365 to your computer and use it in GitHub Desktop.
Untested. This hook will only allow access to ACP if the IP Geolocation matches a defined value. Only works with CloudFlare.
<?php
/**
* hook_cf_country_admin
*
* This hook will only allow access to ACP if the IP Geolocation matches a defined value. Only works with CloudFlare.
*
* @author k0nsl (http://k0nsl.org)
* @link http://k0nsl.org
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* allow only access if HTTP_CF_IPCOUNTRY matches the value in array, if it doesn't we pour out a cryptic message and redirect
*/
function hook_cf_country_admin(&$hook)
{
$req_uri = $_SERVER['REQUEST_URI'];
$reg_pattern = '/adm/';
if (preg_match($reg_pattern, $req_uri)) {
if ( !isset($_SERVER["HTTP_CF_IPCOUNTRY"]) )
return;
if ( !in_array($_SERVER["HTTP_CF_IPCOUNTRY"], array('DK')) )
{
$urel = 'http://k0nsl.org';
echo 'Sorry, but you cannot login at this time.';
header("Refresh: 5; url='.$urlel.'");
exit;
}
}
}
/**
* initialize the hook
*/
$phpbb_hook->register(array('template', 'display'), 'hook_cf_country_admin');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment