Last active
May 11, 2020 13:53
-
-
Save JeroenSteen/c27a8aa0a639da160070fcbb70150146 to your computer and use it in GitHub Desktop.
Allow only one IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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