Php code generationFiles are a technology that php students should know. This not only improves the security of your website, but also stops problems such as machine registration, next let's look at a simpleVerification code generation program
<?
/EckNum. php
Session_start ();
Function random (){
$ Srcstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
Mt_srand ();
$ Strs = "";
For ($ I = 0; $ I <6; $ I ++ ){
$ Strs. = $ srcstr [mt_rand (0, 35)];
}
Return strtoupper ($ strs );
}
$ Str = random (4); // The string generated by the handler as needed
$ Width = 50; // the image width of the verification code
$ Height = 25; // height of the verification code Image
@ Header ("Content-Type: image/png ");
$ _ SESSION ["code"] = $ str;
// Echo $ str;
$ Im = imagecreate ($ width, $ height );
// Background color
$ Back = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF );
// Blur the 97xxoo point color
$ Pix = imagecolorallocate ($ im, 187,230,247 );
// Font color
$ Font = imagecolorallocate ($ im, 41,163,238 );
// Plot the vertices of fuzzy match.
Mt_srand ();
For ($ I = 0; I I <1000; $ I ++)
{
Imagesetpixel ($ im, mt_rand (0, $ width), mt_rand (0, $ height), $ pix );
}
Imagestring ($ im, 5, 7, 5, $ str, $ font );
Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ font );
Imagepng ($ im );
Imagedestroy ($ im );
$ _ SESSION ["code"] = $ str;
?>