PHP Classes

Traffic Jam: Block unwanted bots based on access speed

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 79%Total: 287 All time: 7,533 This week: 41Up
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
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 59
All time rank: 608 in United States United States
Week rank: 47 Up7 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
//traffic jam class 0.1 beta
include('trafficjam.class.php');

$tJam = new trafficJam();

$jamCode = $tJam->jamTraffic();

if( !empty(
$jamCode) ){
   
    include(
'jam_'.$jamCode.'.php');
    exit;
   
}
?>
<html>
    <head>
        <title>Traffic Jam Example</title>
    </head>
    <body>
        <a href="example.php">Click Me</a>
        <p>To test, click link as a normal human would and then click as quickly as possible. Depending on your humanSpeed and jamTime settings, you should get jammed.</p>
        <p>Once jammed, you can refresh the page or visit again later to see countdown to when you will be allowed back in</p>
    </body>
</html>


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 (7)  
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 (7)  /  history  
File Role Description
  Accessible without login Plain text file index.php Aux. Folder access holder

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:287
This week:0
All time:7,533
This week:41Up
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:30