Last active
June 13, 2020 23:38
-
-
Save carl-alberto/6feacbe77426ae63ad4909be72035690 to your computer and use it in GitHub Desktop.
Block IP via php in wp-config.php
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
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