Demo


This is a demonstration of the RainCaptcha. It was built using our RainCaptcha PHP API Wrapper.

Source Code

See RainCaptcha PHP Class page for source code and documentation.

<?php
    require_once('RainCaptcha.php');
    $captcha = new RainCaptcha();
?>
<html>
    <body>
        <form action="handler.php" method="post">
            <table>
                <tr>
                    <th>Captcha</th>
                    <td>
                        <img id="captchaImage" src="<?php echo $captcha->getImage(); ?>" />
                        <br />
                        <input name="captcha" type="text" />
                        <button type="button" onclick="document.getElementById('captchaImage').src = '<?php echo $captcha->getImage(); ?>&morerandom=' + Math.floor(Math.random() * 10000);">Get another CAPTCHA image</button>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="Submit" /></td>
                </tr>
            </table>
        </form>
    </body>
</html>
<html>
    <body>
        <?php
            require_once('RainCaptcha.php');
            $captcha = new RainCaptcha();

            if(isset($_POST['captcha'])) {
                $isCaptchaCorrect = $captcha->checkAnswer($_REQUEST['captcha']);
                
                if($isCaptchaCorrect) {
                    echo 'You have entered <strong>correct</strong> CAPTCHA code!';
                }
                else {
                    echo 'You have entered <strong>wrong</strong> CAPTCHA code! <a href="/form.php">Please try again!</a>';
                }
            }
			
            else {
                echo 'Hacking attempt!';
            }
        ?>
    </body>
</html>

Advertisement