<?php

//  Captcha Script URL
$URL = "http://web11.engr.uconn.edu/cgi-bin/captcha.py";

//  If user entered a response, test it against the Captcha script.
if (isset($_GET["captcha"])) {

    //  Get users response
    $captcha = $_GET["captcha"];

    //  Query captcha script
    $ch = curl_init($URL . "?" . $_GET["captcha"]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $output = curl_exec($ch); 
    curl_close($ch);

    //  Display captcha script result
    $OK = $output == "OK\n";
    print "<h2>Captcha Test Result</h2><hr nospace><br>\n";
    print "User's response is <b>$captcha</b>.<br><br>\n";
    if ($OK) {
        print "<b>User has been verified.</b><br>\n";
    } else {
        print "User has <b>NOT</b> been verified.<br>\n";
    }

//  No user response found, so display captcha code entry form.
} else {
?>
<h2>Captcha Test.</h2><hr nospace><br>
<form action="" method="get">
<img src="<?php print $URL; ?>"><br><br><br>
<i>Enter the text from the image above.</i><br><br><br>
<input type="text" name="captcha" value="" size="8">
<input type="submit" name="submit" value="Submit"><br>
</form>
<?php
}
?>