wolfsoft/botguard-php

PHP 集成库,用于BotGuard网站保护服务。

1.0.2 2019-02-03 21:43 UTC

This package is auto-updated.

Last update: 2024-09-14 21:43:48 UTC


README

Latest Stable Version Build Status codecov License

BotGuard Cloud的集成库。

use BotGuard\BotGuard;
use BotGuard\Profile;

// Initialize BotGuard Service instance
$botguard = BotGuard::instance([
	'server' => 'xxx.botguard.net',
	'backup' => 'yyy.botguard.net',
]);

// Check incoming request
$profile = $botguard->check();

// Do bot mitigation
if ($profile) {
	switch ($profile->getMitigation()) {
		case Profile::MITIGATION_DENY:
		case Profile::MITIGATION_RETURN_FAKE:
			http_response_code(403);
			exit;
		case Profile::MITIGATION_CHALLENGE:
			http_response_code(403);
			$profile->challenge();
			exit;
		case Profile::MITIGATION_REDIRECT:
		case Profile::MITIGATION_CAPTCHA:
			header('Location: ' . $profile->getMitigationURL(), true, 302);
			exit;
	}
}

echo 'Welcome, human';

安装

使用Composer

$ composer require wolfsoft/botguard-php
{
    "require": {
        "wolfsoft/botguard-php": "^1.1"
    }
}
<?php
require 'vendor/autoload.php';

use BotGuard\BotGuard;
use BotGuard\Profile;

// the rest of the code

不使用Composer

为什么您不使用 Composer?从仓库下载 BotGuard.php 并将其保存到项目路径中的某个位置。

<?php
require 'path/to/Profile.php';
require 'path/to/BotGuard.php';

use BotGuard\BotGuard;
use BotGuard\Profile;

// the rest of the code

文档

集成指南