|
The code is as follows:
<?php
/* Site Verification Code Program
* Operating Environment: PHP5.0.18 Debugging through
* Need GD2 Graphics library support (Php_gd2.dll Open in php.ini)
* FileName: showimg.php
* Author: 17php.com
* date:2007.03
*/
//randomly generate a 4-digit number verification code
$num = "";
for ($i =0 $i <4; $i + +) {
$num. = rand (0,9);
}
//4-bit Authenticode can also be generated directly by rand (1000,9999)
//The generated CAPTCHA is written to the session, and the validation page uses the
Session_Start ();
$_session["checknum"] = $num;
//Create picture, define color value
Header ("Content-type:image/png");
Srand (double) microtime () *1000000);
$im = imagecreate (60,20);
$black = imagecolorallocate ($im, 0,0,0);
$gray = imagecolorallocate ($im, 200,200,200);
Imagefill ($im, 0,0, $gray);
//Randomly draw two dashed lines, interfering
$style = Array ($black, $black, $black, $black, $black, $ Gray, $gray, $gray, $gray, $gray);
Imagesetstyle ($im, $style);
$y 1=rand (0,20);
$y 2=rand (0,20);
$y 3=rand (0,20);
$y 4=rand (0,20);
imageline ($im, 0, $y 1, $y 3, img_color_styled);
imageline ($im, 0, $y 2, $y 4, img_color_styled);
A large number of black spots are randomly generated on the canvas, which plays a disturbing role.
For ($i =0 $i <80; $i + +)
{
Imagesetpixel ($im, Rand (0,60), Rand (0,20), $black);
}
The four digits are randomly displayed on the canvas, and the horizontal spacing and position of the characters are randomly generated according to a certain range of fluctuations.
$strx =rand (3,8);
For ($i =0 $i <4; $i + +) {
$strpos =rand (1,6);
Imagestring ($im, 5, $strx, $strpos, substr ($num, $i, 1), $black);
$strx +=rand (8,12);
}
Imagepng ($im);
Imagedestroy ($im);
?>
|