PHP code example of coercive / ghostfield

1. Go to this page and download the library: Download coercive/ghostfield 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/ */

    

coercive / ghostfield example snippets


use  Coercive\Security\GhostField\GhostField;

# Load class, set key
$GhostField = new GhostField('123456abcdef');

# Activate handshake JS (optional)
$GhostField->setSigil();

# Create honeypot fields (empty = automatic)
$GhostField->createFields();

# Add your regular fields
$GhostField->createFields([
    'email',
    'password',
]);

use  Coercive\Security\GhostField\GhostField;

if(!$GhostField->validate($_POST)) {
    echo 'Unallowed';
    die;
}

if($str = $GhostField->getHideJS()): 

use  Coercive\Security\GhostField\GhostField;

foreach ($GhostField->getFields() as $field):