Use this simple script to stop certain users viewing your website.

Place this code at the top of every page you would like to restrict access to. You could also place it in a file called access.php and include() in every page on your website.

<?php
//place the users IP in the ip variable
$ip = $_SERVER['REMOTE_ADDR'];
$connection = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("dbname");
$query = mysql_query("SELECT * FROM banned_users WHERE userip='$ip'");

//check to see if the users IP matches a banned IP
$select_banned = mysql_num_rows($query);

if($select_banned == 1) {
//print a message to the user if they are banned
print "You have been banned from viewing this website.";
//stop the page from being loaded
exit;
}
?>
The above code will check the users IP against the mysql table then try to find matches, then print the error message if a match is found. You will need to enter your own mysql info. We now need to create our mysql table now...

Execute the following SQL code in phpmyadmin. This will create our table.
CREATE TABLE `banned_users` ( `userip` TEXT NOT NULL );


To ban a user, you will need to manually add each IP into the table. You can do this using phpmyadmin, or create a seperate IP adding script.