Skip to content

Instantly share code, notes, and snippets.

@ahmad-moussawi
Created January 31, 2014 13:18
Show Gist options
  • Save ahmad-moussawi/8731970 to your computer and use it in GitHub Desktop.
Save ahmad-moussawi/8731970 to your computer and use it in GitHub Desktop.
function checkIp() {
/**
* Deny if not from the following IPs
*
*/
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$validIps = array(
'89.249.211.162',
'89.249.211.163',
'77.42.245.162',
'89.249.211.164'
);
//$validIps = array();
if (!in_array($ip, $validIps)) {
// http_response_code(401);
header('HTTP/1.1 401 Unauthorized', true, 401);
die('Unauthorized');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment