PHP implementation of simple Chinese verification Code function method

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.