Skip to content

Instantly share code, notes, and snippets.

@carl-alberto
Last active June 13, 2020 23:38
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 carl-alberto/6feacbe77426ae63ad4909be72035690 to your computer and use it in GitHub Desktop.
Save carl-alberto/6feacbe77426ae63ad4909be72035690 to your computer and use it in GitHub Desktop.
Block IP via php in wp-config.php
if ( !file_exists('blocked_ips.txt') ) {
$deny_ips = array(
'127.0.0.1',
);
} else {
$deny_ips = file('blocked_ips.txt');
}
// read user ip adress:
$ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : '';
// search current IP in $deny_ips array
if ( (array_search($ip, $deny_ips))!== FALSE ) {
// address is blocked:
echo 'Sorrty!';
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment