public function createCode()
    {
        $this->code = false;

        switch($this->captcha_type) {
            case self::SI_CAPTCHA_MATHEMATIC:
            {
                do {
                    $signs = array('+', '-', 'x');
                    $left  = mt_rand(1, 10);
                    $right = mt_rand(1, 5);
                    $sign  = $signs[mt_rand(0, 2)];

                    switch($sign) {
                        case 'x': $c = $left * $right; break;
                        case '-': $c = $left - $right; break;
                        default:  $c = $left + $right; break;
                    }
                } while ($c <= 0); // no negative #'s or 0

                $this->code         = "$c";
                $this->code_display = "$left $sign $right";
                break;
            }

            case self::SI_CAPTCHA_WORDS:
                $words = $this->readCodeFromFile(2);
                $this->code = implode(' ', $words);
                $this->code_display = $this->code;
                break;

            default:
            {
                if ($this->use_wordlist && is_readable($this->wordlist_file)) {
                    $this->code = $this->readCodeFromFile();
                }

                if ($this->code == false) {
                    $this->code = $this->generateCode($this->code_length);
                }

                $this->code_display = $this->code;
                $this->code         = ($this->case_sensitive) ? $this->code : strtolower($this->code);
            } // default
        }

        $this->saveData();
    }
public function createCode()
    {
        $this->code = false;

        switch($this->captcha_type) {
            case self::SI_CAPTCHA_MATHEMATIC:
            {
                do {
                    $signs = array('+', '-', 'x');
                    $left  = mt_rand(1, 10);
                    $right = mt_rand(1, 5);
                    $sign  = $signs[mt_rand(0, 2)];

                    switch($sign) {
                        case 'x': $c = $left * $right; break;
                        case '-': $c = $left - $right; break;
                        default:  $c = $left + $right; break;
                    }
                } while ($c <= 0); // no negative #'s or 0

                $this->code         = "$c";
                $this->code_display = "$left $sign $right";
                break;
            }

            case self::SI_CAPTCHA_WORDS:
                $words = $this->readCodeFromFile(2);
                $this->code = implode(' ', $words);
                $this->code_display = $this->code;
                break;

            default:
            {
                if ($this->use_wordlist && is_readable($this->wordlist_file)) {
                    $this->code = $this->readCodeFromFile();
                }

                if ($this->code == false) {
                    $this->code = $this->generateCode($this->code_length);
                }

                $this->code_display = $this->code;
                $this->code         = ($this->case_sensitive) ? $this->code : strtolower($this->code);
            } // default
        }

        $this->saveData();
    }
public function createCode ( ) { $ this -> code = false ; switch ( $ this -> captcha_type ) { case self :: SI_CAPTCHA_MATHEMATIC : { do { $ signs = array ( '+' , '-' , 'x' ) ; $ left = mt_rand ( 1 , 10 ) ; $ right = mt_rand ( 1 , 5 ) ; $ sign = $ signs [ mt_rand ( 0 , 2 ) ] ; switch ( $ sign ) { case 'x' : $ c = $ left * $ right ; break ; case '-' : $ c = $ left - $ right ; break ; default : $ c = $ left + $ right ; break ; } } while ( $ c <= 0 ) ; // no negative #'s or 0 $ this -> code = "$c" ; $ this -> code_display = "$left $sign $right" ; break ; } case self :: SI_CAPTCHA_WORDS : $ words = $ this -> readCodeFromFile ( 2 ) ; $ this -> code = implode ( ' ' , $ words ) ; $ this -> code_display = $ this -> code ; break ; default : { if ( $ this -> use_wordlist && is_readable ( $ this -> wordlist_file ) ) { $ this -> code = $ this -> readCodeFromFile ( ) ; } if ( $ this -> code == false ) { $ this -> code = $ this -> generateCode ( $ this -> code_length ) ; } $ this -> code_display = $ this -> code ; $ this -> code = ( $ this -> case_sensitive ) ? $ this -> code : strtolower ( $ this -> code ) ; } // default } $ this -> saveData ( ) ; }
This method generates a new captcha code.

Generates a random captcha code based on *charset*, math problem, or captcha from the wordlist and saves the value to the session and/or database.
This method generates a new captcha code .