Skip to content

How To Block An IP Address From Visiting A Website

Mrityunjaya P edited this page Apr 19, 2020 · 2 revisions

There are many reasons you may need to block an IP address from visiting your website. For example, to prevent particular users doing malicious things with your website - trying to spam your web forms, or hack your shopping cart, etc. Using PHP, you can easily find your site visitors' website addresses and based on these addresses to redirect them to specific places on your site. If you use such IP ban protection on your website, you will also need to not only list individual addresses to be blocked but also IP masks and IP ranges.

<?php
$ip_block = array(
        '111.65.248.132',
        '216.58.197.119',       
        '192.168.1.100',
        '192.168.1.105',
        '100.88.*.*',
        '122.25.100.*',
        '216.58.197.101-216.58.197.200',
        '98.255.255.100-98.255.255.150'
);
Clone this wiki locally