|
<? Php
/*
* Verification Code Generation Program
*/
$ Letter = '';
// Obtain random numbers
For ($ I = 0; $ I <2; $ I ++ ){
$ Letter. = chr (mt_rand (48, 57 ));
}
// Obtain random letters
For ($ I = 0; $ I <2; $ I ++ ){
$ Letter. = chr (mt_rand (65,90 ));
}
// Reconstruct the Character Sequence
$ Strs = str_split ($ letter );
Shuffle ($ strs );
$ Rndstring = "";
While (list (, $ str) = each ($ strs )){
$ Rndstring. = $ str;
}
// If GD is supported, draw
If (function_exists ("imagecreate "))
{
// Write cookie to the browser
Setcookie ("zjs_ckstr", md5 (strtolower ($ rndstring), time () + 300, '/'); // The verification code is valid for 5 minutes
$ Rndcodelen = strlen ($ rndstring );
// Image size
$ Im = imagecreate (100,30 );
// $ Im = imagecreatefromgif ("code.gif ");
// Font
$ Font_type = dirname (_ FILE _). "/data/font/AvantGardeBookBT. ttf ";
// Background color
$ Backcolor = imagecolorallocate ($ im, 255,255,255 );
// Font color
// Imagettftext is not supported
$ FontColor = ImageColorAllocate ($ im, 0, 0 );
// Supports imagettftext
$ FontColor2 = ImageColorAllocate ($ im, 0, 0 );
// Shadow
$ FontColor1 = ImageColorAllocate ($ im, 255,255, 25 );
// Add background noise
$ PixColor = imagecolorallocate ($ im, 199,199,199); // miscellaneous color
For ($ j = 0; $ j <1000; $ j ++ ){
Imagesetpixel ($ im, rand (0,100), rand (0, 30), $ pixColor );
}
// Add a background line
For ($ j = 0; $ j <= 3; $ j ++ ){
// Background line color
$ LineColor1 = ImageColorAllocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
// Size of the background line direction
Imageline ($ im, rand (), $ lineColor1 );
}
$ Strposs = array ();
// Text
For ($ I = 0; $ I <$ rndcodelen; $ I ++ ){
If (function_exists ("imagettftext ")){
$ Strposs [$ I] [0] = $ I * 16 + 17; // X axis
$ Strposs [$ I] [1] = mt_rand (20, 23); // y axis
Imagettftext ($ im, 5, 5, $ strposs [$ I] [0] + 1, $ strposs [$ I] [1] + 1, $ fontColor1, $ font_type, $ rndstring [$ I]);
} Else {
Imagestring ($ im, 5, $ I * 16 + 7, mt_rand (2, 4), $ rndstring [$ I], $ fontColor );
}
}
// Text
For ($ I = 0; $ I <$ rndcodelen; $ I ++ ){
If (function_exists ("imagettftext ")){
Imagettftext ($ im, 16, 5, $ strposs [$ I] [0]-1, $ strposs [$ I] [1]-1, $ fontColor2, $ font_type, $ rndstring [$ I]);
}
}
Header ("Pragma: no-cachern ");
Header ("Cache-Control: no-cachern ");
Header ("Expires: 0rn ");
// Output a specific image format with a priority of gif-> jpg
If (function_exists ("imagegif ")){
Header ("content-type: image/gifrn ");
Imagegif ($ im );
} Else {
Header ("content-type: image/policrn ");
Imagejpeg ($ im );
}
ImageDestroy ($ im );
}
?>
|