This article mainly introduces the PHP implementation of the simple Chinese verification code function, combined with an example of the PHP Chinese verification Code to implement the steps and Operation methods, including graphic creation, coding operations, session operation and other related skills, the need for friends can refer to the next
Specific as follows:
img.php
<?phpsession_start ();/*for ($i =0; $i <4; $i + +) {$rand. = Dechex (rand (1,15));} $_session[check_pic] = $rand; */$image = Imagecreatetruecolor (+), $BG = Imagecolorallocate ($image, 0, 0, 0); $color = i Magecolorallocate ($image, 255, 255, 255),//imagestring ($image, Rand (1,6), Rand (3,60), Rand (3,15), $rand, $color); for ($ i=0; $i <3; $i + +) {$color 2 = imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255)); Imageline ($image, Rand (0,100), 0, 2, $color);} RAND ()---->0-max less than 100for ($i =0; $i <200; $i + +) {Imagesetpixel ($image, Rand ()%100, Rand ()%30, $color 2);} $str = Iconv ("GBK", "Utf-8", "Zhong"); $str = "China"; $_session[check_pic] = $STR;//resolve Chinese, the page itself is Utf-8$str = mb_convert_encoding ( $str, "Html-entities", "utf-8");//2: Font size 3: Tilt angle x, y coordinate imagettftext ($image, N, 0, A, a, $color, ' Msyh. TTF ', $str);//Output Picture header ("Content-type:image/jpeg;charset=utf-8"); imagejpeg ($image);/* Modify Eclipse Configuration, You can make the default encoding of the new project for Eclipse directly UTF-8 on the menu bar Window->preferences->general->workspace->texT file encoding change it to UFT-8. */?>
sub.php
<?php Header ("Content-type:text/html;charset=utf-8"); Session_Start (); if ($_post[check]) { if ($_post[check]==$_session[check_pic]) { echo "Captcha is correct:". $_session[check_pic]; } else { echo "Captcha error:". $_session[check_pic]; } }? ><form action= "" method= "post" > <br/> <input type= "text" Name= "Check" ><br/> <input type= "Submit" value= "Submission" ></form>
Run as follows:
The above is the whole content of this article, I hope that everyone's study has helped.