PHP code example of sohophp / security

1. Go to this page and download the library: Download sohophp/security library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sohophp / security example snippets


$dos = new Sohophp\Security\Dos();
$dos->run();


$config = new Sohophp\Security\DosConfig();
//开启调试消息
$config->setDebug(true);
//开启详情记录
$config->setSpread(true);
//添加IP白名单
$config->addWhiteList('::1','127.0.0.1');
//单页每秒最大请求数
$config->setPageCount(3);
//站点每秒请求数
$config->setSiteCount(100);
//加入黑名单秒数,每次请求重置拉黑时间
$config->setBlockingPeriod(30);
//监听全部METHOD
//$config->setListenMethods(["ANY"]);
//监听以下METHOD
$config->setListenMethods(["POST","DELETE","PUT","OPTIONS"]);
$dos = new Sohophp\Security\Dos($config);
//自动运行,阻止时出现403 
//$dos->run();
//测试使用
try{
    if($dos->refused()){ 
        echo '<pre>';
        print_r($dos->getDebugMessages());
        echo '</pre>';
        die("已被拉黑");
    }
}catch (Exception $exception){
    die($exception->getMessage());
}