Title: IP blocking
Last modified: November 15, 2022

---

# IP blocking

 *  [underro](https://wordpress.org/support/users/underro/)
 * (@underro)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/)
 * Hello there.
    I have a question about IP blocking: I want to add a long long 
   list of IPs, to block them, in the Comment blacklist field area (countries on
   several continents). I tried this before in .htaccess, but I got a warning about
   too much information here. If I add in this area (Comment blacklist field) all
   this long list, will it write them in .htaccess? It will affect the speed (requests).
   Is it advisable to do this? Thanks.
    -  This topic was modified 3 years, 6 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Everything else WordPress
      topic

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16200695)
 * Try one of these plugins: [https://wordpress.org/plugins/tags/ip-blocker/](https://wordpress.org/plugins/tags/ip-blocker/)
 *  Thread Starter [underro](https://wordpress.org/support/users/underro/)
 * (@underro)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201216)
 * Thanks for the reply.
    I’ve seen them before, but wanted to avoid using a plugin
   if possible.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201272)
 * This could certainly be developed as a custom code snippet. The hook [https://developer.wordpress.org/reference/hooks/init/](https://developer.wordpress.org/reference/hooks/init/)
   would be suitable I think. There you would have to read the calling IP via _$\
   _SERVER[‘REMOTE\_ADDR’]_ and compare it with the list you created. If it is included,
   you just do a `wp_die()`.
 *  Thread Starter [underro](https://wordpress.org/support/users/underro/)
 * (@underro)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201515)
 * That’s right.
    I have this:
 *     ```
       <?php $deny = array("111.111.111", "222.222.222", "333.333.333");
       if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
          header("location: https://site.com/");
          exit();
       } ?>
       ```
   
 * And with this [https://www.countryipblocks.net/acl.php](https://www.countryipblocks.net/acl.php)
   to get the addresses.
 * The only problem is that I still can’t replace ip examples with a list of ip 
   ranges.
 * But I was curious if the default solution from WordPress is better in terms of
   efficiency/resources/request.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201548)
 * There is a “default solution” for this from WordPress. My description above requires
   custom programming.
 * So far you have only talked about IP list, not IP ranges. This is more a question
   of how to solve this in PHP. Here someone wrote an answer to this: [https://stackoverflow.com/questions/11121817/how-to-check-an-ip-address-is-within-a-range-of-two-ips-in-php](https://stackoverflow.com/questions/11121817/how-to-check-an-ip-address-is-within-a-range-of-two-ips-in-php)
 * If you do it via the init hook, it should be efficient enough. However, it would
   be even better if you put the blocking in your server environment. Talk to your
   hosting support about it.
 *  Thread Starter [underro](https://wordpress.org/support/users/underro/)
 * (@underro)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201664)
 * To my knowledge, ip blocker from cpanel also writes in .htaccess.
    Anyway, I 
   will also ask the hosting. I will also study this post from stackowerflow in 
   more detail. Thanks for the answers and involvement.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘IP blocking’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [underro](https://wordpress.org/support/users/underro/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/ip-blocking-7/#post-16201664)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
