HostGator Reseller Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Web & Server Administration

Web & Server Administration Discussions about websites and server administration, mod_rewrite, managing .htaccess, Apache and Windows Server configuration, LINUX, Security, Traffic Analysis, Sitemaps, robots.txt etc...

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2008, 07: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

  #2 (permalink)  
Old 01-23-2008, 03:33 PM
blokey blokey is offline
WMG Resident Alien
 
Join Date: Mar 2007
Posts: 93
iTrader: (0)
blokey is on a distinguished road
Default

The multiple IP code can be rewritten more efficiently like this:
--
$banned_addrs = array(
'nnn.nnn.nnn.nnn',
'nnn.nnn.nnn.nnn',
);
if (in_array($_SERVER['REMOTE_ADDR'], $banned_addrs))
die('<p>You are banned.</p>');
--
I attempted to wrap that in a CODE or PHP block but vBulletin seems to be a bit broken.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 05:35 AM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
Go Daddy $1.99 Domains Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0