Spawn Framework · Contact · Community · Tutorial · Documentation · Download · About

Learn :: Captcha

Configuration:

//library/sf/config/captcha.php
$config['width']=150;
$config['height']=50;

//image background color (rgb)
$config['background']=null;//array(1,1,1) //if gradient ==false
$config['gradient']=true;
	
//create random lines 	
$config['randomLinesBottom']=true;		
$config['randomLinesTop']=true;		
	
//if text is mathematical operation	
$config['math']=false;
$config['math_int1']=array(1,10);
$config['math_int2']=array(1,10);
$config['math_math']=array('+','-','*');
	
//number of characters if not math	
$config['lenght']=4;
$config['randomText']=true;
$config['fontPath']= 'Media/Font/';
$config['fonts']= array('Garuda-Bold.ttf');

//special effects
//Options: blur, embossing, edgedetect, meanRemoval
$config['effects']=array();
);

How to use in project:

namespace Controller
class Home extends \Spawn\Controller
{
      public function indexAction()
      {
          $captcha = new Captcha;

         //valid if send post 
          if( $this -> request -> post('captcha','') != '' ){
             //if captcha is declared
             if($captcha -> isDeclared()){
                if( $captcha -> isValid( $this -> request -> post('captcha') ) ){
                   echo '<p>Is valid!</p>';
                }else{
                   echo '<p>Is not valid!</p>';
                }
             }
          }

          //create form
          echo '<form action="" method="post">';
          echo 'Code: <input type="text" name="captcha" /><br/>';
          echo '<img src="/captcha" />';
          echo '<input type="submit" value="valid" /> </form>';
      }
}