the following code I debug all through. Run authpage.php.
?
/*
* Filename:authpage.php
*/
Srand (double) microtime () *1000000);
//Verify that user input is consistent with the verification code
if (isset ($_post[' authinput ') )
{
if (strcmp ($_post[' authnum '],$_post[ ' authinput ']) ==0)
echo "Verify success!" ";
Else
echo "Validation failed! ";
}
//Generate a new four-bit integer verification code
while (($authnum =rand ()%10000) <1000);
?>
<form action=authpage.php method=post>
<table>
Please enter the verification code: <input type=text name=authinput style= "width:80px" ><br>
<input type=submit name= "Authentication" value= "Submit authentication Code" >
<input type=hidden name=authnum value=< echo $authnum;?>>
>
</table>
</form>
------------------------------------------------------------------------------------------------------- ------
?
/*
* Filename:authimg.php
*/
//Generate CAPTCHA picture
Header ("Content-type:image/png");
Srand (double) microtime () *1000000);
$im = imagecreate (58,28);
$black = imagecolorallocate ($im, 0,0,0);
$white = imagecolorallocate ($im, 255,255,255);
$gray = imagecolorallocate ($im, 200,200,200);
Imagefill ($im, 68,30, $gray);
//Draw four-bit integer captcha into the picture
imagestring ($im, 5, 8, $HTTP _get_vars[' Authnum '), $white);
for ($i =0; $i <50; $i + +)//Add interference pixel
{
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $gray);
}
imagepng ($im);
Imagedestroy ($im);
?>
__________________
java->struts