// ------------------------------------------------------------------------
// define these in your main index.php or a constants config file
define('DEVELOPERS', '127.0.0.1|123.123.123.123|111.222.333');
define('REDIRECT_PUBLIC', 'http://en.gravatar.com/<whatever>');
// ------------------------------------------------------------------------
// developersOnly
// ipDepth allows you to be less restrictive and accept an entire work subnet
if ( ! function_exists('developersOnly'))
{
function developersOnly($ipDepth = 4, $boolResult = false)
{
$ip = explode('.', $_SERVER['REMOTE_ADDR']);
$check_ip = array();
for($i = 0; $i < $ipDepth; $i++)
$check_ip[] = $ip[$i];
$check_ip = implode(".", $check_ip);
if(strpos(DEVELOPERS, $check_ip) === false):
if($boolResult)
return false;
else
redirect(REDIRECT_PUBLIC);
exit;
endif;
return true;
}
}
// ------------------------------------------------------------------------
// usage examples
// developersOnly(); // require IP match and redirect if not developer
// developersOnly(3); // require IP subnet match and redirect if not developer
// develoeprsOnly(4, true); // return a boolean result instead of redirect