BotDetect PHP CAPTCHA Integration Quickstart
1. Copy Captcha Library Files
Download the BotDetect PHP Captcha library, and copy the lib
contents (botdetect.php
and the botdetect
subfolder) to your website source.
2. Show a Captcha Challenge on the Form
On the very top of the source file for the PHP form you want to protect against bots, add:<?php session_start(); ?> <?php require("botdetect.php"); ?>On the PHP form you want to protect against bots, add:
<link type="text/css" rel="Stylesheet" href="<?php echo CaptchaUrls::LayoutStylesheetUrl() ?>" /> </head> […] <?php // Adding BotDetect Captcha to the page $ExampleCaptcha = new Captcha("ExampleCaptcha"); $ExampleCaptcha->UserInputID = "CaptchaCode"; echo $ExampleCaptcha->Html(); ?> <input name="CaptchaCode" id="CaptchaCode" type="text" />
3. Check User Input During Form Submission
When the form is submitted, the Captcha validation result must be checked:<?php if ($_POST) { // if your form postbacks to a separate PHP file, first create the instance // $ExampleCaptcha = new Captcha("ExampleCaptcha"); // validate the Captcha to check we're not dealing with a bot $isHuman = $ExampleCaptcha->Validate(); if (!$isHuman) { // TODO: Captcha validation failed, show error message } else { // TODO: Captcha validation passed, perform protected action } } ?>
In-Depth PHP CAPTCHA Instructions and Explanations
Detailed PHP Captcha instructions and explanations can be found in the PHP Captcha integration how to guide.
Other BotDetect PHP CAPTCHA Quickstarts
Laravel 5.2 CAPTCHA | CakePHP 3 CAPTCHA | CodeIgniter 3.0 CAPTCHA |
Laravel 5.1 CAPTCHA | CakePHP 2 CAPTCHA | CodeIgniter 2.2 CAPTCHA |
Laravel 5.0 CAPTCHA | Symfony 3 CAPTCHA | |
Laravel 4.2 CAPTCHA | Symfony2 CAPTCHA |
Current BotDetect Versions
-
BotDetect ASP.NET CAPTCHA
2019-07-22v4.4.2 -
BotDetect Java CAPTCHA
2019-07-22v4.0.Beta3.7 -
BotDetect PHP CAPTCHA
2019-07-22v4.2.5