PHP Classes

File: examples/random.php

Recommend this page to a friend!
  Classes of sameer shelavale   PHP Multi CAPTCHA   examples/random.php   Download  
File: examples/random.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Multi CAPTCHA
Perform CAPTCHA validation with multiple solutions
Author: By
Last change: fixed the include filename in examples.
Date: 9 years ago
Size: 1,657 bytes
 

Contents

Class file image Download
<?php

include_once( "../src/Captcha.php");


$captcha = new \MultiCaptcha\Captcha([
   
'secret'=> "form1-secret-key",
   
'options' => [

       
'honeypot' => array(
           
'description'=> "Leave this field empty if you are human",
           
'class' => 'error'
       
),
       
'math' => array(
           
'description'=> "Answer following question if you are human",
           
'level' => 4
       
),
       
'image' => array(
           
'maxCodeLength' => 8,
           
'font'=>'../src/types/image/comic.ttf',
           
'width'=>180
       
),
       
'ascii' => array(
           
'maxCodeLength' => 8,
           
'fonts'=>array(
               
'banner'=> 4,
               
'doom'=> 8,
               
'small'=>'8'
           
)
        ),
       
'gif' => array(
           
'maxCodeLength' => 8,
           
'font'=>'../src/types/image/comic.ttf',
           
'width'=>180,
           
'height'=>60,
           
'totalFrames'=>50,
           
'delay'=>20
       
)
    ],
   
'refreshUrl'=>'random.php?captcha=refresh',
   
'helpUrl'=>'http://github.com/sameer-shelavale/multi-captcha'
] );

if( isset(
$_GET['captcha']) && $_GET['captcha'] == 'refresh' ){
    echo
$captcha->refresh();
    exit;
}elseif( isset(
$_REQUEST['submit'] ) ){
    if(
$captcha->validate( $_POST, $_SERVER['REMOTE_ADDR'] ) ) {
        echo
"Correct.";
    }else{
        echo
"Wrong: ". $captcha->error;
    }
}
?>
<h2>Display a random captcha from types initialized using "<i>options</i>" parameter.</h2>
<form action="" method="post">
    <?php
   
echo $captcha->render() ;
   
?>
<input type="submit" name="submit" value="Submit">

</form>