Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Block User From Visiting Website Using PHP

Friday, Jan 27, 2017


Sometimes there are some user in a website who try to break website policies, not doing things as per website guidelines, post malicious data in website, put comment on website that harm website image then website owner's take some serious action against those user by getting there ip address and temporary or permanently block user from visiting website. So, in this tutorial we will show you how to block user from visiting your website using PHP.You may also like get visitor details using PHP.

Block User From Visiting Website Using PHP

To Block User From Visiting Website It Takes Only One Step:-

  1. Make a PHP file to block user from visiting website

Step 1.Make a PHP file to block user from visiting website

We make a PHP file and save it with a name block.php

// Database Structure 
CREATE TABLE 'blocked_user' (
 'ip' text NOT NULL,



 $get_result = mysql_query("select * from blocked_user where ip='$user_ip'");
  echo "<h1>Your Are Blocked From Visiting This Website</h1>";
<div id="wrapper">
<h1>Block User From Visiting Your Website Using PHP</h1>

 Your Website Content


In this step we create a database table called 'blocked_user' to store ip address of blocked user and then we connect to database and and get the ip of user when user visit website and check if user ip is present in our database if ip is present then we display the block message and hide rest of the content and if user ip is not present it means the user is not blocked then we display website as usual.You may also like get user location using ip address.

That's all, this is how to block user from visiting website using PHP.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH