<head>
<title>
Captcha Test
</title>
<script>
function loadImage() {
        var obj = document.getElementById("captcha");
        var date = new Date();
        obj.src = '/cgi-bin/captcha.py?xxx=' + date.getTime();
        return false;
}
</script>
</head>
<?php

//  Captcha Script URL
$URL = "http://web9.uits.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 id="captcha" src="<?php print $URL; ?>">
<br/>
<a href="#" onClick="return loadImage();"><i>reload image</i></a>
<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
}
?>