PHP code example of jqqjj / simple-anti-robot
1. Go to this page and download the library: Download jqqjj/simple-anti-robot 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/ */
jqqjj / simple-anti-robot example snippets
composer
use Jqqjj\SimpleAntiRobot\Manager;
use Jqqjj\SimpleAntiRobot\Adapter\DBTableGateway;
//Create a PDO object
$pdo = new \PDO('mysql:host=localhost;port=3306;dbname=yourdbname','dbuser','dbpasswd');
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//Create an adapter(Only MySQL adapter is supported Currently)
$adapter = new DBTableGateway($pdo);
$object = new Manager($adapter);
//Run the codes when the client do something incorrectly
$object->attemptFailure();
//Run the codes when the client do things as you want to be
$object->attemptSuccess();
//Check it, it will return false when the client is a robot
if($object->isHuman()){
//human
}
if($object->isRobot()){
//robot
}
//Finally, output the cookie
$object->outputCookie();
//OR
header("Set-Cookie:".$object->getOutputCookieString());