PHP code example of zrashwani / key-pic

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

    

zrashwani / key-pic example snippets



use Zrashwani\KeyPic\KeyPic;

$keypicObj = new KeyPic($psrRequest); //initiate and configure keypic object
$keypicObj = $keypicObj->setFormID('YOUR_KEYPIC_FORM_ID') //set form ID
                       ->setDebug(true) // set debug mode
                       ->setTokenInputName("keypic_token"); //hidden input name
$token = $keypicObj->getToken();

if($psrRequest->getMethod() == "POST"){
    $data         = $psrRequest->getParsedBody();    
    $email        = $data['EMAIL_INPUT'];
    $username     = $data['NAME_INPUT'];
    $message      = $data['MESSAGE_INPUT'];
    
    //Detect if entry is Spam? from 0% to 100%
    $spam = $keypicObj->isSpam($email, $username, $message);
    if($spam === false){
       echo "Cannot determine spam percentage.";
    }elseif($spam > 60){ //if spam percentage larger than certain number
        echo "user and/or submitted data seems spammy, spam percentage = ".$spam;
    }else{
        echo "Not Spam";
    }
}
html
<form action="" method="post">
    <!-- Your form elements here -->
     echo $keypicObj->renderHtml();