image.func.php
<?php require_once (' string.func.php '); function Verifyimage ($type =1, $length =4, $pixel =0, $line =0, $sess _name= "verify") {session_start (); /* Define length and Width */$width =80; $height =30;/* Create canvas */$image =imagecreatetruecolor ($width, $height); /* This function is used to match the color of the graphic for use by other drawing functions. The parameter image represents the handle of the graph. Parameters red, green, blue are the three primary colors of the color, the value from 0 to 255 .... I hereby define black and white */$white =imagecolorallocate ($image, 255, 255, 255); $black = Imagecolorallocate ($image, 0,0,0); /* This function shades the enclosing rectangular area of the picture. The Parameters x1, y1, and x2, and Y2 are the coordinates of the rectangular diagonal respectively. The parameter col represents the color to be painted */imagefilledrectangle ($image, 1, 1, $width-2, $height-2, $white); The/*buildrandomstring function is used to generate a verification code */$chars =buildrandomstring ($type, $length); /* Pass the verification code to the SESSION to determine if the user input is correct */$_session[$sess _name]= $chars; /* Define the Font library */$f/* Use the loop to write the Captcha one-by-one to the picture */for ($i =0; $i < $length; $i + +) {$size =mt_rand (14,18); $angle =mt_rand ( -15,15); /* The horizontal and vertical coordinates of the verification code */$x =5+ $i * $size; $y =mt_rand (20,26); $color =imagecolorallocate ($image, Mt_rand (50,190), Mt_rand (50,200), Mt_rand (50,90)); $f ><?php function buildrandomstring ($type =1, $length =4) {if ($type ==1) { /*join functions convert the array to a string: The join () function is an alias for the implode () function */ $chars =join ("", Range (0,9));} ElseIf ($type ==2) { /*array_merge function Merge array */ $chars =join ("", Array_merge (Range ("A", "Z"), Range ("A", "Z")));} ElseIf ($type ==3) {$chars =join ("", Array_merge (Range ("A", "Z"), Range ( "a", "Z"), Range (0,9)));} if ($length > Strlen ($chars)) { exit ("insufficient string Length");} /* Scrambled String */$chars =str_shuffle ($chars); return substr ($chars, 0, $length); }?>
The above describes the PHP implementation to generate verification code instance sharing, including PHP, verification code aspects of the content, I hope that the PHP tutorial interested in a friend helpful.