Skip to content

Instantly share code, notes, and snippets.

@treffynnon
Last active December 16, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treffynnon/5413728 to your computer and use it in GitHub Desktop.
Save treffynnon/5413728 to your computer and use it in GitHub Desktop.
A simple PHP snippet to verify authorisation via IP address. Supports wildcard/partial IP addresses.
<?php
$allowable_ips = array(
'192.168.0.',
'8.8.8.8',
);
$is_allowed = (bool) array_filter($allowable_ips, function($value) {
return (substr($_SERVER['REMOTE_ADDR'], 0, strlen($value)) == $value);
});
if(!$is_allowed) {
die('Denied.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment