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.
To Block User From Visiting Website It Takes Only One Step:-
- 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, ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 <?php $host="localhost"; $username="root"; $password=""; $databasename="sample"; $connect=mysql_connect($host,$username,$password); $db=mysql_select_db($databasename); $user_ip=$_SERVER['REMOTE_ADDR']; $get_result = mysql_query("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>"; } exit(); ?> <html> <body> <div id="wrapper"> <h1>Block User From Visiting Your Website Using PHP</h1> <div> Your Website Content </div> </div> </body> </html>
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.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery