PHP code example of williamsampaio / simple-captcha

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

    

williamsampaio / simple-captcha example snippets


 $captcha = new SimpleCaptcha();

 $captcha = new SimpleCaptcha("H@ck3R'D_C0@r1", true);

 $captcha->getKey();

<img src=" echo $captcha->getImg() 



illiamSampaio\SimpleCaptcha\SimpleCaptcha;

session_start();

$captcha = new SimpleCaptcha();

if(isset($_POST['captcha'])){

    if($_POST['captcha'] == $_SESSION['captcha']->getKey()){
        echo "<h1 style='color:green;'>Captcha valid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }else{
        echo "<h1 style='color:red;'>Captcha invalid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }

}

$_SESSION['captcha'] = $captcha;