<?php session_start(); //Import the Class File include "../captcha.class.php"; //Initialization & Setings $captcha = new realCaptcha(array("height" => 200, "width" => 500, "source" => realCaptcha::DICTIONARY, "number_of_words" => 2, "fonts_dir" => "../resources/fonts/", "dictionary_file" => "../resources/dictionary.php")); //Generating the Captcha... $c = $captcha->generate(); //Output Captcha to Browser, as JPG Image with 40% Quality $c->output("jpg", 40); //Save Text to Session $_SESSION["captcha_text"] = $c->text;
<?php //Import the Class File include "../captcha.class.php"; //Initialization & Setings $captcha = new realCaptcha(array("height" => 200, "width" => 500, "source" => realCaptcha::DICTIONARY, "number_of_words" => 2, "fonts_dir" => "../resources/fonts/", "dictionary_file" => "../resources/dictionary.php")); //Generating the Captcha... $c1 = $captcha->generate(); $c1->output("png", 40); //Output Captcha to Browser, as JPG Image with 40% Quality $c1->file("output/c1.png", "png", 50); //Save Captcha to PNG File $c1->file("output/c1.jpg", "jpg", 50); //Save Captcha to JPG File $c1->file("output/c1.gif", "gif"); //Save Captcha to GIF File $_SESSION["captcha_text"] = $c1->text; //Store Captcha Text in Session $_SESSION["captcha_array"] = $c1->array; //Store Captcha Words Array in Session //----- Change Settings $captcha->set(array("height" => 200, "width" => 400, "source" => realCaptcha::RANDOM)); $c2 = $captcha->generate(); $c2->file("output/c2.png", "png", 50); //---- Define Temporary settings while calling the Generator Method $c3 = $captcha->generate(array("background_color" => array(255, 0, 0), "text_color" => array(255, 255, 255))); $c3->file("output/c3.jpg", "jpg", 50); //---- Take Direct Input $captcha->set(array("source" => realCaptcha::INPUT)); //Pass a String $c4 = $captcha->generate("Example");
public function dictionaryText(&$settings = FALSE) { //init settings $settings = !$settings ? $this->settings : $settings; if (!file_exists($settings["dictionary_file"])) { throw new Exception("Error Finding dictionary file {$settings["dictionary_file"]}", 4); } $size = filesize($settings["dictionary_file"]); //Minimum number of characters required $minimum = 50 * $settings["number_of_words"]; //starting character from a random point in the file keeping minimum characters into consideration.... $start = rand(0, $size - $minimum); $file = fopen($settings["dictionary_file"], "r"); //Set File pointer to random point... fseek($file, $start); //read minimum number of characters and strip all non english characters //$raw = preg_replace("/[^a-zA-Z\s]/", "", fread($file, $minimum)); //read minimum number of characters and replace all non english characters $raw = realCaptcha::remove_accents(fread($file, $minimum)); $array = str_split($raw); //Final Array container... $text_array = array(); //current Letter... $pointer = 0; //current word being fetched... $index = 0; //Temporary text container $temp = ""; //if the first " " (space) character was reached or not... $first_reach = FALSE; //infinite loop, until break... while (TRUE) { //if current character doesn't exist, stop the loop if (empty($array[$pointer])) { break; } //if current character is a letter and a space has already been reached, add the character to temporary... if ($first_reach && ctype_alnum($array[$pointer])) { $temp .= $array[$pointer]; } //if current character is a space and a space has already been reached before if ($first_reach && $array[$pointer] == " ") { $temp_size = strlen($temp); //check temporary size and is under 3 characters long, reject and turncate temporary... if ($temp_size < 3) { $temp = ""; } else { // if over 3, then add the word to delivery storage, turncate temp $text_array[$index] = $temp; $temp = ""; //If the max number of words are reached, stop the loop if ($index == $settings["number_of_words"] - 1) { break; } else { // If not max, prepare for new word insertion... $index++; } } } //check for the first space character encountered... if (!$first_reach && $array[$pointer] == " ") { $first_reach = TRUE; } $pointer++; } return $text_array; }