<?php
 
// Starting the session (used to store the captcha solution)
 
session_start();
 
?>
 
<body>
 
    <head>
 
        <title>String Captcha</title>
 
        <style type="text/css">
 
            .captchaLink
 
            {
 
                width: 16px;
 
                height: 16px;
 
                border: none;
 
                cursor: pointer;
 
            }
 
            
 
            .captchaLink:hover
 
            {
 
                color: #ff0000;
 
            }
 
            
 
            .inline
 
            {
 
                float: left;
 
            }
 
        </style>
 
    </head>
 
    <body>
 
        <div class="inline">
 
            <img src="./captcha/string.php" alt="captcha" /> 
 
        </div>
 
        <div class="inline">
 
            <a onclick="document.getElementById('demo').play()" class="captchaLink" >▷</a><br />
 
            <a onclick="document.getElementById('demo').pause()" class="captchaLink" >⌷⌷</a>
 
        </div>
 
        <div style="clear: both;"></div>
 
        <audio id="demo"> 
 
            <source src="./audio/string_audio.php?aud=<?php echo time(); ?>" type="audio/mpeg" />
 
            Your browser does not support the audio element.
 
        </audio>
 
        <p>Do not include spaces. All lower case.</p>
 
        <form action="display_string.php" method="POST">
 
            <input type="text" name="captcha" /><br />
 
            <input type="submit" name="submit" value="Submit" />
 
            <input type="reset" value="Reset" />
 
        </form>
 
    </body>
 
</html>
 
<?php
 
if(isset($_POST['submit']))
 
{
 
    // Checking the session captcha vs the submitted captcha
 
    if($_SESSION['captcha'] == $_POST['captcha'])
 
    {  // It was a match
 
        echo '<p>Correct!</p>';
 
    }
 
    else
 
    {  // It was NOT a match
 
        echo '<p>Incorrect, correct answer was ' . $_SESSION['captcha'] . '</p>';
 
    }
 
}
 
?>
 
    </body>
 
</html>
 
 |