wolfsoft/botguard-php

PHP Integration Library for BotGuard web site protection service.

1.0.2 2019-02-03 21:43 UTC

This package is auto-updated.

Last update: 2024-05-14 20:57:29 UTC


README

Latest Stable Version Build Status codecov License

An integration library for 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';

Installation

With 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

Without Composer

Why are you not using Composer? Download BotGuard.php from the repo and save the file into your project path somewhere.

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

use BotGuard\BotGuard;
use BotGuard\Profile;

// the rest of the code

Documentation

Integration Guide