Skip to content

Instantly share code, notes, and snippets.

@JeroenSteen
Last active May 11, 2020 13:53
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 JeroenSteen/c27a8aa0a639da160070fcbb70150146 to your computer and use it in GitHub Desktop.
Save JeroenSteen/c27a8aa0a639da160070fcbb70150146 to your computer and use it in GitHub Desktop.
Allow only one IP
<?php
$allowed_ip = ''; //https://watismijnip.nl/
// Function to get the client ip address
function get_client_ip_env() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
if(get_client_ip_env() === $allowed_ip) {
} else {
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment