PHP Classes
elePHPant
Icontem

Traffic Jam: Block unwanted bots based on access speed

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-10-14 (4 years ago) RSS 2.0 feedStarStarStarStar 79%Total: 259 All time: 7,637 This week: 285Up
Version License PHP version Categories
traffic-jam 0.1GNU General Publi...5HTTP, PHP 5, Security
Description Author

This class can be used to block unwanted bots based on access speed.

It keeps track of the history of accesses of bots based on their IP address. The accesses information is stored in a history file named based on the IP address.

If the bot accesses more than a given number per second, it will be blocked for a given period of time.

The class can be configured with a whitelist to allow accesses of given user agents that will not be throttled.

Innovation Award
PHP Programming Innovation award nominee
January 2016
Number 2


Prize: One downloadable copy of PhpED Professional
Sometimes sites are abused by bots that crawl them and extract their content.

Since bot scripts often send too many requests to the site servers, that may cause server overload. The site owner may also not be happy with the possibility that other sites that may be stealing their content.

This class may help fighting this kind of abuse by keeping track of the frequency of the accesses performed by bots. It can be used to block bots that are sending requests at a frequency above an acceptable limit.

Manuel Lemos
  Performance   Level  
Name: Dave Smith <contact>
Classes: 47 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 29x

Winner: 6x

 

Details
Class: trafficjam
Version: 0.1 bets 10/14/2015

Copyright 2015 Wagon Trader, All Rights Reserved


Description:

This class will block unwanted bots and traffic based on speed the page is being accessed.

Configure whitelist of bots allowed which will not be throttled.
Specify length of time an ip will be blocked
Provide friendly notifications in the event a human gets blocked

Files:

trafficjam.class.php - Main class

example.php - Simple application example

jam_100.php - Display notification for access violation

jam_200.php - Display notification for unwanted bot

/history - folder to hold ip history files

Installation:

Upload files to a web accessible location on your server (eg. public_html)


Configuration:

/history folder needs read and write access (666) or (777) on linux servers

You can change the following settings in the class to meet your specific needs...

$humanSpeed - Number of accesses per second a human would access the site. The lower the number, the more
    likely the ip will be jammed.

$jamTime - Time in seconds that an ip will be jammed.

$fileFolder - Name of folder that holds history data. For security purposes, you can change the folder name
    and set this value to the correct folder.

$dataDelim - delimiter used in history files. A complex delimiter avoids the need to manage commas, tabs, etc...

$fileExt = extension history file to use. tjm is the default, so files will be named [ip_number].tjm


Usage:

Refer to example.php file for usage example.

Refer to trafficjam.class.php file for instructions on using methods

Changelog

0.1 beta

Initial beta release
  Files folder image Files  
File Role Description
Files folder imagehistory (1 file)
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file jam_100.php Example Jammed display
Accessible without login Plain text file jam_200.php Example Jammed display
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file manual.txt Doc. Documentation
Plain text file trafficjam.class.php Class Main Class

  Files folder image Files  /  history  
File Role Description
  Accessible without login Plain text file index.php Aux. Folder access holder

 Version Control Unique User Downloads Download Rankings  
 0%
Total:259
This week:0
All time:7,637
This week:285Up
User Ratings User Comments (1)
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:100%StarStarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:79%StarStarStarStar
Rank:39