/** * Shows a Captcha with a text Field * * @param bool $ShowImage If true Shows the captcha otherwise validates * @return bool */ public static function StaticCaptcha($ShowImage = false) { require_once __DIR__ . '/captcha/securimage.php'; $options = array('database_driver' => Securimage::SI_DRIVER_MYSQL, 'database_host' => HOST_Name, 'database_user' => MySQL_User, 'database_pass' => MySQL_Pass, 'database_name' => MySQL_DB, 'database_table' => MySQL_Pre . 'CaptchaCodes', 'captcha_type' => Securimage::SI_CAPTCHA_MATHEMATIC, 'no_session' => true); if ($ShowImage) { $captchaId = Securimage::getCaptchaId(true, $options); $Captcha = '<input type="hidden" id="captchaId" name="captchaId"' . ' value="' . $captchaId . '" />' . '<img id="siimage"' . ' src="ShowCaptcha.php?captchaId=' . $captchaId . '"' . ' alt="captcha image" />' . '<input class="form-TxtInput" placeholder="Solve the math above" ' . 'type="text" name="captcha_code" value="" required />'; echo $Captcha; } else { $captcha_code = self::GetVal($_POST, 'captcha_code'); if ($captcha_code !== null) { $VerifyID = self::GetVal($_POST, 'captchaId'); $ValidCaptcha = Securimage::checkByCaptchaId($VerifyID, $captcha_code, $options); return $ValidCaptcha; } } }
error_reporting(E_ALL); ini_set('display_errors', 1); // defines Securimage class require_once '../securimage.php'; // define options for securimage $options = array('database_driver' => Securimage::SI_DRIVER_MYSQL, 'database_host' => 'localhost', 'database_user' => 'securimage', 'database_pass' => 'password1234', 'database_name' => 'test', 'no_session' => true); // get the captcha ID from the url (if supplied) $captchaId = isset($_GET['id']) ? $_GET['id'] : ''; // if the validate option is set if (isset($_GET['validate'])) { // $_GET['id'] should also be set // get the user input of the captcha code $input = isset($_GET['input']) ? $_GET['input'] : ''; // call Securimage::checkCaptchaId to validate input // returns true if the code and id are a valid pair, false if not if (Securimage::checkByCaptchaId($captchaId, $input, $options) == true) { echo "<h2>Success</h2>" . "<span style='color: #33cc00'>The captcha code entered was correct!</span>" . "<br /><br />"; } else { echo "<h2>Incorrect Code</h2>" . "<span style='color: #f00'>Incorrect captcha code, try again.</span>" . "<br /><br />"; } } else { if (isset($_GET['refresh'])) { $captcha = Securimage::getCaptchaId(true, $options); $data = array('captchaId' => $captcha); echo json_encode($data); exit; } else { if (isset($_GET['display'])) { // display the captcha with the supplied ID from the URL // construct options specifying the existing captcha ID // also tell securimage not to start a session
* to securimage_show.php providing the captcha ID. */ // set debugging error_reporting(E_ALL); ini_set('display_errors', 1); // defines Securimage class require_once '../securimage.php'; // get the captcha ID from the url (if supplied) $captchaId = isset($_GET['id']) ? $_GET['id'] : ''; // if the validate option is set if (isset($_GET['validate'])) { // get the user input of the captcha code $input = isset($_GET['input']) ? $_GET['input'] : ''; // call Securimage::checkCaptchaId to validate input // returns true if the code and id are a valid pair, false if not if (Securimage::checkByCaptchaId($captchaId, $input) == true) { echo "<h2>Success</h2>" . "<span style='color: #33cc00'>The captcha code entered was correct!</span>" . "<br /><br />"; } else { echo "<h2>Incorrect Code</h2>" . "<span style='color: #f00'>Incorrect captcha code, try again.</span>" . "<br /><br />"; } } else { if (isset($_GET['display'])) { // display the captcha with the supplied ID from the URL // construct options specifying the existing captcha ID // also tell securimage not to start a session $options = array('captchaId' => $captchaId, 'no_session' => true); $captcha = new Securimage($options); // show the image, this sends proper HTTP headers $captcha->show(); exit; }