PHP Classes

How to Implement a PHP DDOS Protection Script Using the Package Protect Your Website from DDoS Attack: Show an error when a server gets too many requests

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-08-16 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 54 This week: 54All time: 10,605 This week: 1Up
Version License PHP version Categories
ddos 1.2MIT/X Consortium ...5Networking, PHP 5, Security
Description 

Author

This package can show an error when a server gets too many requests,

It can take the IP address of the user accessing a site served by the current PHP Web script.

The package can check a database that keeps track of the previous accesses to verify if the current access is being sent from a computer that sent too many requests.

When many accesses have been sent recently from the computer with the same IP address, the package sends an error response and the current script should not proceed to serve the normal content.

Picture of The Algoslingers
  Performance   Level  
Name: The Algoslingers <contact>
Classes: 9 packages by
Country: Ghana Ghana
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Instructions

composer require thealgoslithealgoslingers/ddos Usage <?php

require vendor autoload

require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$ddos = new DDoS();

$ddos->log(); Note • There are two optional params accepted. The first param is an 'ip address' and the second is 'options'. Both are optional.

<?php $ddos = new DDoS($ip_address, $options); IP Address • By default, DDoS use the ip address from the user making the request. • You can manually monitor or log a preferred ip address.

Example: <?php

require vendor autoload

require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

$ddos = new DDoS($demo_ip);

$ddos->log(); Options param The $options is an array of DDoS settings. Here is the list:

cache: This is set TRUE or FALSE(FALSE by default). It only has effect on the ip2location whether to cache its dataset (for faster ip lookup) or not. WARNING: This should be set TRUE once per session. Else, the caching will keep restarting anytime this feature is enabled. Make sure you have enough RAM to enable this feature.

log_file: This option is a path to .txt file to log requests. Please make sure you create the file before setting this option(path/to/the/log/file.txt). By default, DDoS create a log file on its own.

rate and timesamp: These two options work together. They specify how many requests allowed(rate) per day/hours/minutes/etc(timesamp). The timesamp option should be in seconds. By default, it is 100 requests per 600(10 minutes).

Example - All together <?php

require vendor autoload

require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

// set options $options = array( "cache" => FALSE, "log_file" => "path/to/your/log/file.txt", "rate" => 15 // 15 request, "timesamp" => 600 // 10 minutes in seconds );

$ddos = new DDoS($demo_ip, $options);

$ddos->log(); • log() in DDoS also accept one optional param which is a function. This function is executed by DDoS when users hit their limit. • By default, when a user hits its limit, he is automatically redirected to a "429 Too Many Requests". • To prevent this from happening, you can tell DDoS to execute your function if a user hit the limit.

Example <?php

require vendor autoload

require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

// set options $options = array( "cache" => FALSE, "log_file" => "path/to/your/log/file.txt", "rate" => 15 // 15 request, "timesamp" => 600 // 10 minutes in seconds );

// Define what DDoS should do if // users hit the limit function myFunc(){ // Do something when user hit the limit }

$ddos = new DDoS($demo_ip, $options);

$ddos->log('myFunc');

• Please note that this function will only be called when the user hits his request limit.

note DDoS is highly recommended for applications which have main controller or the MVC architecture; where all requets are managed by a single file controller.

Documentation

ddos

Protect Your Website from DDoS Attacks

Installation

  composer require thealgoslithealgoslingers/ddos

Usage

<?php

## require vendor autoload
require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$ddos = new DDoS();

$ddos->log();

Note

? There are two optional params accepted. The first param is an 'ip address' and the second is 'options'. Both are optional.

<?php
$ddos = new DDoS($ip_address, $options);

IP Address

? By default, DDoS use the ip address from the user making the request. ? You can manually monitor or log a preferred ip address.

Example:

<?php

## require vendor autoload
require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

$ddos = new DDoS($demo_ip);

$ddos->log();

Options param

The $options is an array of DDoS settings. Here is the list:

cache: This is set TRUE or FALSE(FALSE by default). It only has effect on the ip2location whether to cache its dataset (for faster ip lookup) or not. WARNING: This should be set TRUE once per session. Else, the caching will keep restarting anytime this feature is enabled. Make sure you have enough RAM to enable this feature.

log_file: This option is a path to .txt file to log requests. Please make sure you create the file before setting this option(path/to/the/log/file.txt). By default, DDoS create a log file on its own.

rate and timesamp: These two options work together. They specify how many requests allowed(rate) per day/hours/minutes/etc(timesamp). The timesamp option should be in seconds. By default, it is 100 requests per 600(10 minutes).

Example - All together

<?php

## require vendor autoload
require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

// set options
$options = array(
 "cache" => FALSE,
 "log_file" => "path/to/your/log/file.txt",
 "rate" => 15 // 15 request,
 "timesamp" => 600 // 10 minutes in seconds
);

$ddos = new DDoS($demo_ip, $options);

$ddos->log();

? log() in DDoS also accept one optional param which is a function. This function is executed by DDoS when users hit their limit. ? By default, when a user hits its limit, he is automatically redirected to a "429 Too Many Requests". ? To prevent this from happening, you can tell DDoS to execute your function if a user hit the limit.

Example

<?php

## require vendor autoload
require_once 'vendor/autoload.php';

use thealgoslingers\ddos;

$demo_ip = '0.0.0.0';// provided ip address

// set options
$options = array(
 "cache" => FALSE,
 "log_file" => "path/to/your/log/file.txt",
 "rate" => 15 // 15 request,
 "timesamp" => 600 // 10 minutes in seconds
);

// Define what DDoS should do if
// users hit the limit
function myFunc(){
  // Do something when user hit the limit
}

$ddos = new DDoS($demo_ip, $options);

$ddos->log('myFunc');

? Please note that this function will only be called when the user hits his request limit.

note

DDoS is highly recommended for applications which have main controller or the MVC architecture; where all requets are managed by a single file controller.


Details

{ "name": "thealgoslingers/ddos", "description": "Safeguard your website from DDoS attack.", "keywords": ["library", "ddos", "DDoS attack","thealgoslingers", "the algoslingers", "prevent DDoS attak", "website security"], "type": "library", "require-dev": { "phpunit/phpunit": "^5.7" }, "license": "MIT", "authors": [ { "name": "thealgoslingers" } ], "autoload": { "psr-4": { "thealgoslingers\\": "src" }, "files": [ ] }, "require": { "ip2location/ip2location-php": "^9.7" } }

  Files folder image Files (4)  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (4)  /  src  
File Role Description
  Plain text file DDoS.php Class Class source

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  
 100%
Total:54
This week:54
All time:10,605
This week:1Up