PHP Classes

PHP Form SPAM Protection without CAPTCHA: Validate human users who submit form fields

Recommend this page to a friend!
  Info   View files Documentation   View files View files (53)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-03-08 (7 days ago) RSS 2.0 feedNot enough user ratingsTotal: 52 This week: 52All time: 10,588 This week: 1Up
Version License PHP version Categories
no-captcha-php 1.0BSD License5HTML, PHP 5, Validation, Security
Description 

Author

This package can validate human users who submit form fields.

It can generate HTML and JavaScript to be used in forms to detect when a natural person submitted the form.

The package provides several classes that implement various rules that applications can use to verify human users who submit forms.

Currently, it provides rule classes that can:

- Use cookies to detect users

- Use a hidden checkbox that robots may check

- Use hidden fields that store encrypted keys valid for a limited period

- Use JavaScript to fill a hidden input value

- Use JavaScript to insert a hidden form input dynamically

- Use the PHP session variable to store the time a form is generated, and only accept submissions if they happen within a limited period.

Picture of Gabriel Alejandro López López
  Performance   Level  
Name: Gabriel Alejandro López ... <contact>
Classes: 3 packages by
Country: United States United States

Documentation

No Captcha Form Spam Filter

No Captcha Form Spam Filter is a PHP utility library for dealing with spam bots using unobtrusive and user friendly techniques.

Applying this techniques will help to reduce the span in your sites in more than 90% and users will not be annoyed with intrusive Captchas or extra fields.

Installation

You can download it and place it on your third party libraries folder but we highly recommend that you install it through composer.

Either run

$ composer require daxslab/no-captcha

or add

"daxslab/no-captcha": "~1.0"

to the require section of your composer.json file.

The NoCaptchaAntiSpam Class

The NoCaptchaAntiSpam Class can be used to declare Protection Rules, Include security code in forms and check if the form submission does not trigger any rule validation.

For creating an instance of the NoCaptchaAntiSpam Class, the create() static function can be used:


use daxslab\nocaptcha\NoCaptchaAntiSpam;
use daxslab\nocaptcha\rules\CssHiddenFieldRule;

// Declare no captcha anti spam object with CSS based hidden field check
$noCaptchaAntiSpam = NoCaptchaAntiSpam::create([
        'rules' => [
            CssHiddenFieldRule::create([
                // form input field name
                'name' => 'css_hidden_field',
            ])
        ],
]);

Including form elements

Using the NoCaptchaAntiSpam created instance you can include the needed elements inside a form with the renderRules() function:

<form id="contactForm" method="post">
    <div class="form-group">
        <label for="contactName">Name</label>
        <input class="form-control" name="contact_name" id="contactName" placeholder="Enter name">
    </div>
    
    <!--  Include rules form elements  -->
    <?= $noCaptchaAntiSpam->renderRules() ?>
    
    <button type="submit" name="submit_button" class="btn btn-primary">Submit</button>
</form>    

Verifying form submission

Using the checkSubmit() function from the NoCaptchaAntiSpam created instance you can check if any of the declared Rules triggers when the form is submitted:

if ($_POST){
    if ($noCaptchaAntiSpam->checkSubmit()){
        echo 'Form submitted correctly';
    } else {
        echo 'Bot detected';
    }
}

Rules

Rule classes implements different security checks including:

  • `CssHiddenFieldRule`: A honeypot field hidden using CSS
  • `JavascriptGeneratedHiddenFieldRule`: A honeypot field generated using JavaScript
  • `JavascriptFilledInputRule`: A JavaScript filled hidden input
  • `SessionTimeTrapRule`: A time trap using session stored variables
  • `FormTimeTrapRule`: A time trap using a form field
  • `CookieCheckRule`: A cookie verification

A NoCaptchaAntiSpam instance can contain one or multiple rules.

Random field names

Random field names can be applied for an extra security layer, they are stored in PHP sessions and rules field names will change making difficult to bots identify them. Random field names can be applied to single rules or multiple rules.

Documentation

For extended documentation and examples you can put the doc folder behind a PHP capable web server.


  Files folder image Files  
File Role Description
Files folder imagedoc (10 files, 2 directories)
Files folder imagelib (1 file, 1 directory)
Files folder imagetests (3 files, 4 directories)
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  doc  
File Role Description
Files folder imageassets (2 directories)
Files folder imagecommon (2 files)
  Accessible without login Plain text file cookie_check.php Example Example script
  Accessible without login Plain text file css_hidden_field_honeypot.php Example Example script
  Accessible without login Plain text file form_time_trap.php Example Example script
  Accessible without login Plain text file index.php Aux. Auxiliary script
  Accessible without login Plain text file javascript_filled_input.php Example Example script
  Accessible without login Plain text file javascript_generat..._field_honeypot.php Example Example script
  Accessible without login Plain text file multiple_random_field_names.php Example Example script
  Accessible without login Plain text file multiple_rules.php Example Example script
  Accessible without login Plain text file random_field_name.php Example Example script
  Accessible without login Plain text file session_time_trap.php Example Example script

  Files folder image Files  /  doc  /  assets  
File Role Description
Files folder imagecss (2 files)
Files folder imagejs (3 files)

  Files folder image Files  /  doc  /  assets  /  css  
File Role Description
  Accessible without login Plain text file bootstrap.min.css Data Auxiliary data
  Accessible without login Plain text file default.css Data Auxiliary data

  Files folder image Files  /  doc  /  assets  /  js  
File Role Description
  Accessible without login Plain text file bootstrap.bundle.min.js Data Auxiliary data
  Accessible without login Plain text file highlight.pack.js Data Auxiliary data
  Accessible without login Plain text file jquery.slim.min.js Data Auxiliary data

  Files folder image Files  /  doc  /  common  
File Role Description
  Accessible without login Plain text file footer.php Aux. Auxiliary script
  Accessible without login Plain text file header.php Aux. Auxiliary script

  Files folder image Files  /  lib  
File Role Description
Files folder imagerules (8 files)
  Plain text file NoCaptchaAntiSpam.php Class Class source

  Files folder image Files  /  lib  /  rules  
File Role Description
  Plain text file BaseRule.php Class Class source
  Plain text file CookieCheckRule.php Class Class source
  Plain text file CssHiddenFieldRule.php Class Class source
  Plain text file FormTimeTrapRule.php Class Class source
  Plain text file JavascriptFilledInputRule.php Class Class source
  Plain text file JavascriptGeneratedHiddenFieldRule.php Class Class source
  Plain text file RuleInterface.php Class Class source
  Plain text file SessionTimeTrapRule.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageacceptance (7 files)
Files folder imageacceptancenojs (4 files)
Files folder imageunit (2 files)
Files folder image_support (4 files, 1 directory)
  Accessible without login Plain text file acceptance.suite.yml Data Auxiliary data
  Accessible without login Plain text file acceptancenojs.suite.yml Data Auxiliary data
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data

  Files folder image Files  /  tests  /  acceptance  
File Role Description
  Plain text file CookieCheckCest.php Class Class source
  Plain text file CssHiddenFieldCest.php Class Class source
  Plain text file FormBassedTimeTrapCest.php Class Class source
  Plain text file HelloCest.php Class Class source
  Plain text file JavascriptFilledInputCest.php Class Class source
  Plain text file JavascriptGeneratedHiddenFieldCest.php Class Class source
  Plain text file SessionBassedTimeTrapCest.php Class Class source

  Files folder image Files  /  tests  /  acceptancenojs  
File Role Description
  Plain text file CssHiddenFieldNoJsCest.php Class Class source
  Plain text file HelloNoJsCest.php Class Class source
  Plain text file JavascriptFilledInputNoJsCest.php Class Class source
  Plain text file JavascriptGenerate...enFieldNoJsCest.php Class Class source

  Files folder image Files  /  tests  /  unit  
File Role Description
  Plain text file BaseRuleTest.php Class Class source
  Plain text file NoCaptchaAntiSpamTest.php Class Class source

  Files folder image Files  /  tests  /  _support  
File Role Description
Files folder imageHelper (4 files)
  Plain text file AcceptancenojsTester.php Class Class source
  Plain text file AcceptanceTester.php Class Class source
  Plain text file FunctionalTester.php Class Class source
  Plain text file UnitTester.php Class Class source

  Files folder image Files  /  tests  /  _support  /  Helper  
File Role Description
  Plain text file Acceptance.php Class Class source
  Plain text file Acceptancenojs.php Class Class source
  Plain text file Functional.php Class Class source
  Plain text file Unit.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:52
This week:52
All time:10,588
This week:1Up