<html>
<head>
<title>Capcha Challenge for SOS project</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!-- //PHP Code by Angelos Stavrou for the SOS project  
       Copyright 2003 Columbia University
//-->


<SCRIPT language=JavaScript>
<!--// activate cursor in first textarea
function setFocus() {
    if (window.document){
    document.Captcha.answer.focus();
    return true;
    }
}
         
//-->

</SCRIPT>

<body bgcolor="lightgrey" text="#000000" ONLOAD="setFocus()">
<center>
<h1> <font color ="darkred"> CAPTCHA User Verification <BR> MOVE Project </font></h1>
<?php

// File Containing Db-Connect info
require("dbconnect.inc.php4");

/* Connecting, selecting database */
    $link = mysql_connect($mysql_host, $mysql_user, $mysql_password)
        or die("Could not connect to Mysql Host $mysql_host");
    debug("Connected successfully to $mysql_host::$mysql_db");
    mysql_select_db("$mysql_db") or die("Could not select database $mysql_db");
    $random = mt_rand(1,560);
    debug("The number is $random");    
/* Performing SQL query */
    $query = "SELECT * FROM $mysql_table WHERE cap_id = $random";
    $result = mysql_query($query) or die("Query failed");
   
// make sure that we received some data from our query 
    $numr = mysql_num_rows ($result) 
    or die ("The query: '$query' did not return any data"); 
    debug("The number of rows is $numr");
// Get the data from the DB    
    $row = mysql_fetch_row ($result); 
    $filename = $row[1];
    $temp_filename = md5(uniqid(rand(),1)); // better, difficult to guess
    $temp_filename = "/tmp/$temp_filename";
    debug("Temporary Filename is: $temp_filename"); 
// simlink the image from filesystem to a temp location
// and inject it into the browser    
    $image_file = "$image_directory/$filename.jpg";
    symlink($image_file,"$image_tmp_dir/$temp_filename.jpg");
    symlink("$answer_directory/$filename","$temp_filename");
    debug("The file is $image_file");
    print "<BR><img alt=\" \" src=\"/images/$temp_filename.jpg\">\n";

// For Debug purposes
function debug ($arg_1){
	global $debug;
	if ($debug){
		print "$arg_1<BR>";
	}
}


echo "<p><h3>Please type the text you see in the above picture</h3></p>\n ";
echo "<form name=\"Captcha\" method=\"POST\" ACTION=\"confirm.php\">\n";
echo " <input type=\"text\" name=\"answer\" maxlength=\"12\">\n";
print "<input type=\"hidden\" name=\"captcha\" value=\"$temp_filename\">\n";
echo " <input type=\"submit\" name=\"Submit\" value=\"Submit\">\n";
echo " <input type=\"reset\" name=\"Reset\" value=\"Reset\"\n>";
?>
</form>
<h4> please hit refresh/reload to view another image </h4>
<p><BR>
This Captcha library was obtained from <A href="http://www.captcha.net"> CMU CAPTCHA Project </A>
</body>
</html>
