Clan Adverts

www.afgserv.com

 

User Agent Banner

Description: User Agent Banner
Version: 1.0
Added on: 24 February 2007
Author: unkonw
Difficulty Level: Very Easy
Views: 323
Detailed Profile

Ever had those annoying search bots or weird 'webcrawlers' creeping into your website and ripping you of your bandwidth? Heres a simple solution to eliminate these threats.

Code:

$agent = array("badbot1", "badbot2", "badbot3");
for($i=0;$i < sizeof($agent);$i++){
if(!empty($agent[$i])){
if(eregi($agent[$i], $_SERVER['HTTP_USER_AGENT'])){die();}
}
}


Lets break the code down

Code:

$agent = array("badbot1", "badbot2", "badbot3");

This is the agent array. You add as many of the agents you want to 'block' from entering your site in this list. You can add as many as you want.

Code:
for($i=0;$i < sizeof($agent);$i++){
if(!empty($agent[$i])){
if(eregi($agent[$i], $_SERVER['HTTP_USER_AGENT'])){die();}
}
}


This piece of code does 2 things.

1)
First it counts the number of 'agents' in the ARRAY and lists them out one by one

2)
The second thing it does is it checks if the array BOX is empty. If it isn't empty, it compares the CURRENT USER's User agent to the user agent in the array. If they match or have a similar match, it automatically 'dies' (kills the operation and terminates all processes of the site).


Simple? This piece of code can be used immediately on ANY SITE. Simply paste it at the begining of the page code, just before the opening