How to Block User From Visiting Website Using PHP

There are many reasons you may need to block an IP address from visiting your website. 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. You may also like How to Get User Location Using IP Address In PHP .

PHP Code

<?php
    $user_ip=$_SERVER['REMOTE_ADDR'];
    $get_result = mysqli_query($con, "select * from blocked_user where ip = '".$user_ip."' ");
    if(mysql_num_rows($get_result)>0)
    {
        echo "<h1>Your Are Blocked From Visiting This Website</h1>";
    }
?>

Leave a Reply

Your email address will not be published. Required fields are marked *