View Single Post
  #1 (permalink)  
Old 01-23-2008, 08:48 AM
c4gamerz c4gamerz is offline
WMG Newcomer
 
Join Date: Aug 2007
Posts: 6
iTrader: (0)
c4gamerz is on a distinguished road
Default HOW TO : Ban An IP Address from your Website

May be some people wanna hack your website or make you angry cause he put order in your shop with no payment and wrong address or spam in your forum, blog ect.
How To Ban IP Address? First you need register in histats.com to get free visitor list, include their IP address.
Then Use the below code, simply past one of the codes in a file named ban.php

For a Single IP:
Quote:
<?php
// For a single user ban
$ban_ip = 'xxx.xxx.xxx.xxx'; // ip address of the person you want to ban

// DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING
$visitor_ip = $_SERVER['REMOTE_ADDR']; // the ip address of the visitor
if($visitor_ip == $ban_ip)
{
die("<br><br><center><h2>You are banned from this site!<br>Please contact / email Web Administrator admin@yourdomain.com</h2></center>);
}

?>
For Multiple IP's:
Quote:
<?php
// For a multiple user ban
$ban_ip = ("xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx"); // put ip addresses, separated by commas
// DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING
$visitor_ip = $_SERVER['REMOTE_ADDR'];
$ip_list = explode(",", $ban_ip);
foreach($ip_list as $ip)
{
if($visitor_ip == $ip)
{
die("<br><br><center><h2>You are banned from this site!<br>Please contact / email Web Administrator admin@yourdomain.com</h2></center>");
}
}

?>
Then at the top of index.php files put this code:
Quote:
require 'ban.php';
This script will ban the person(s) from viewing the site.

You could use .htaccess to ban users like so:

Code:
RewriteCond %{REMOTE_ADDR} ^0\.0\.0\.0$ [OR]
RewriteCond %{REMOTE_ADDR} ^0\.0\.0\.1$
RewriteRule ^.*$ - [G]
This way if sy visit your site with 0.0.0.0 IP address, he/she will get a nice 410 Gone error message

Enjoy :P
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block