PHP Chinese Character Verification Code

Source: Internet
Author: User
Tags border color php form

Recently because of the requirements of the project, the need to use Chinese character verification code, so studied a, here to post code to share with you. The following is the use of PHP to generate Chinese character verification code and the specific usage and function code.

Usage is as follows:

<?php
Create_excode (4)//code for generating four Chinese characters

Chinese character Verification Code picture:

The specific function code is as follows:

<?php * * $length Verification code number of Chinese characters/function Create_excode ($length) {$randChar =array ("Hao", "ratio", "No", "surprise", "Static", "see", "Friends", "before", "Flower", "Open", "dragon", "Fall", "righteousness", "get", "Jiang", "No", "Yi", "Tiger", "Wang", "Tian", "Wai", "Yun", "Volume", "" City "," Ding "," Zhong "," Cheng "," person "," production "," name "," only "," Yu "," Jin "," Guo "," Mei "," Coin "," East
	"," said the wood, "The Water," fire "," soil "," seven "," Nine "," eight "," Work "," code "," figure "," member "," Electricity "," big "," second "," Shu "," Ren ");
	Header ("Content-type:image/png"); $charWidth =30;//the width of each character $image _x= $length * $charWidth; Picture width $image _y=40; Picture height $noise _num=100* $length; The number of miscellaneous points $line _num=13;
	Number of interference lines $image =imagecreate ($image _x, $image _y); $w = $h =0;//picture section highly initialized imagecolorallocate ($image, 250,250,250); Set Picture background color//imagecolorallocate ($image, 0xff,0xff,0xff);//white background $rectangle _color=imagecolorallocate ($image, 0xAA, 0XAA,0XAA); Border color $noise _color=imagecolorallocate ($image, 0x00,0x00,0x00); The pragma color $font _size=18;//font size $font The position of the _y=29;//character at the baseline on the y-axis $font _face= "Heiti.ttf"; Font//Add clutter for ($i =0 $i < $noise _num $i + +) {Imagesetpixel ($image, Mt_rand (0, $image _x), Mt_rand (0, $image _y), $noise _
	color);
	//Generate Authenticode $x = 2; $seSsion_code= ""; For ($i =0 $i < $length; $i + +) {$font _color=imagecolorallocate ($image, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255 ));
		Font Color $code = $randChar [Mt_rand (0,count ($randChar)-1)];
		Imagettftext ($image, $font _size,mt_rand ( -6,6), $x, $font _y, $font _color, $font _face, $code);
		$x +=30;
	$session _code.= $code;
	The value of the verification code is stored in the session @session_start ();
	$_session["Checkcode"]= $session _code; For ($i =0 $i < $line _num $i + +) {$fontcolor =imagecolorallocate ($image, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (
		0,255)); 
	Imagearc ($image, Mt_rand ( -10, $w), Mt_rand ( -10, $h), Mt_rand (30,300), Mt_rand (20,200), 55,44, $fontcolor); }//www. Alixixi.com/php-function/1010.html for ($i =0 $i <255; $i + +) {$fontcolor =imagecolorallocate ($image, Mt_rand (0,255)
		, Mt_rand (0,255), Mt_rand (0,255)); 
	Imagesetpixel ($image, Mt_rand (0, $w), Mt_rand (0, $h), $fontcolor);  Imagerectangle ($image, 0,0, $image _x-1, $image _y-1, $rectangle _color);
	Add a Border imagepng ($image);
Imagedestroy ($image); }

Chinese character Verification Code code download (containing font file)

Articles that you may be interested in

    • PHP extracts the birthday date in the ID number and the function to verify that it is a minor
    • PHP Generate dynamic Captcha picture (GIF)
    • PHP form field Format validation class
    • PHP Build Verification Code function
    • PHP Gets the function of the first letter of Chinese pinyin (really can be used)
    • PHP to convert Simplified Chinese characters to traditional methods
    • js,php Regular validation is a mixture of numbers and letters (6-15-bit)
    • thinkphp automatic verification and automatic filling invalid solution


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.