Digital Verification Code
?
/*
* Filename:authpage.php
*/
Session_Start ();
// Srand (Double) microtime () *1000000);
$authnum = $_session [ '' Authnum '' ];
// Verify that user input is consistent with the authentication code
if ( isset ( $_post [ '' Authinput '' ]))
{
if ( strcmp ( $_post [ '' Authinput '' ] , $_session [ '' Authnum '' ]) == 0 )
Echo " Verify Success! " ;
Else
Echo " validation failed! " ;
}
// to generate a new four-bit integer verification code
while (($authnum =rand ()%10000) <1000);
?>
< Form Action = test4 . php method = Post >
< Table >
Please enter the verification code: < input type = Text name = authinput Style = " width:80px " >< BR >
< input type = Submit Name = " Validate " value = " Submit Verification Code " >
< input type = Hidden name = Authnum Value =<? Echo $authnum ; ?>>
< img SRC = authimg . PHP ? Authnum =<? Echo $authnum ; ?>>
</ Table >
</ form >
authimg.php
? PHP
// Generate Captcha Picture
Header ( " Content-type:image/png " );
Srand (( Double ) Microtime () * 1000000 ); // Sow a seed that generates random numbers to facilitate the use of the following random number generation
Session_Start (); // storing random numbers in session
$_session [ '' Authnum '' ] = "" ;
$im = Imagecreate ( the , - ); // make picture background size
$black = Imagecolorallocate ( $im , 0 , 0 , 0 ); // set Three Colors
$white = Imagecolorallocate ( $im , 255 , 255 , 255 );
$gray = Imagecolorallocate ( $im , A , A , A );
Imagefill ( $im , 0 , 0 , $gray ); // using area filling method, setting (0,0)
while (( $authnum = Rand () % 100000 ) < 10000 );
// to draw a four-bit integer verification code into a picture
$_session [ '' Authnum '' ] = $authnum ;
Imagestring ( $im , 5 , Ten , 3 , $authnum , $black );
// Using Col color to draw the string s to the image represented by images of the x,y coordinates at the top left corner is 0, 0.
If font is 1,2,3,4 or 5, the built-in font is used
for ( $i = 0 ; $i < A ; $i ++ ) // adding interference pixels
{
$randcolor = Imagecolorallocate ( $im , Rand ( 0 , 255 ) , Rand ( 0 , 255 ) , Rand ( 0 , 255 ));
Imagesetpixel ( $im , Rand () % - , Rand () % - , $randcolor );
}
Imagepng ( $im );
Imagedestroy ( $im );
?>