Modified A Very Good php Verification Code (supports Chinese)

Source: Internet
Author: User

Php Verification Code
Captcha. class. php

Copy codeThe Code is as follows: <? Php
Class Captcha
Private $ width;
Private $ height;
Private $ codeNum;
Private $ code;
Private $ im;
Function _ construct ($ width = 80, $ height = 20, $ codeNum = 4)
$ This-> width = $ width;
$ This-> height = $ height;
$ This-> codeNum = $ codeNum;
Function showImg ()
// Create an image
$ This-> createImg ();
// Sets the interference element.
$ This-> setDisturb ();
// Set the verification code
$ This-> setCaptcha ();
// Output image
$ This-> outputImg ();
Function getCaptcha ()
Return $ this-> code;
Private function createImg ()
$ This-> im = imagecreatetruecolor ($ this-> width, $ this-> height );
$ BgColor = imagecolorallocate ($ this-> im, 0, 0, 0 );
Imagefill ($ this-> im, 0, 0, $ bgColor );
Private function setDisturb ()
$ Area = ($ this-> width * $ this-> height)/20;
$ DisturbNum = ($ area> 250 )? 250: $ area;
// Add point interference
For ($ I = 0; $ I <$ disturbNum; $ I ++ ){
$ Color = imagecolorallocate ($ this-> im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ this-> im, rand (1, $ this-> width-2), rand (1, $ this-> height-2), $ color );
// Add an arc
For ($ I = 0; $ I <= 5; $ I ++ ){
$ Color = imagecolorallocate ($ this-> im, rand (128,255), rand (125,255), rand (100,255 ));
Imagearc ($ this-> im, rand (0, $ this-> width), rand (0, $ this-> height), rand (30,300), rand (20,200 ), 50, 30, $ color );
Private function createCode ()
$ Str = "23456789 abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ ";
For ($ I = 0; $ I <$ this-> codeNum; $ I ++ ){
$ This-> code. = $ str {rand (0, strlen ($ str)-1 )};
Private function setCaptcha ()
$ This-> createCode ();
For ($ I = 0; $ I <$ this-> codeNum; $ I ++ ){
$ Color = imagecolorallocate ($ this-> im, rand (50,250), rand (100,250), rand (128,250 ));
$ Size = rand (floor ($ this-> height/5), floor ($ this-> height/3 ));
$ X = floor ($ this-> width/$ this-> codeNum) * $ I + 5;
$ Y = rand (0, $ this-> height-20 );
Imagechar ($ this-> im, $ size, $ x, $ y, $ this-> code {$ I}, $ color );
Private function outputImg ()
If (imagetypes () & IMG_JPG ){
Header ('content-type: image/jpeg ');
Imagejpeg ($ this-> im );
} Elseif (imagetypes () & IMG_GIF ){
Header ('content-type: image/gif ');
Imagegif ($ this-> im );
} Elseif (imagetype () & IMG_PNG ){
Header ('content-type: image/png ');
Imagepng ($ this-> im );
} Else {
Die ("Don't support image type! ");

Demo. phpCopy codeThe Code is as follows: <? Php
Require_once 'captcha. class. php ';
$ Captcha = new Captcha (80, 30, 4 );
$ Captcha-> showImg ();

The above supports English, and a Chinese-supported verification code is attached to the students home.Copy codeThe Code is as follows: <? Php
For more information, see ITBBS.
Modify contact author mailbox:
Header ("Content-type: image/PNG ");
$ Str = "first, when there is a conflict with everyone, the main person will use work hours for them to make Chinese products. When I arrive, he will make achievements. For the lower-level students, he will build a ministry of people. the outsourcers can go to the same industry to say that they are too desperate, and after many sub-accounts, they can go from social networks and small hosts, and also rely on their own power lines. The high volume of electricity, the long party has to go through the real-time and deep-seated methods. zheng sanhao's ten-day war had no prefix for farming and other anti-body fight routes. The newly opened things were changed from when two or more tianzi event teams were approved and thought-provoking. guan Dian Yu Zhong his thoughts and in-room because of the day-benefit phase by the pressure officer gas industry on behalf of the whole group number fruit period guide each base or month Mao ran asked than exhibition that it did not see governance I propose five solutions to the forest's rice clusters. I only want four horses to recognize the article, but the article is more grams and the leading public holes are connected to the seat transport and flying crude oil. I am very determined that Shi Qiang is very rare and has gone through a total of direct mission to create another cut nine you take the west holding the total material re-election of the mind to adjust the seven What mountain Cheng baibao more see must be really hot Protection Committee the hand-modified management department has already completed the repair and identification of the disease, and the old-light and special-style 6-type secondary security belt shows the completion of each East-increased traffic back to the south-guang Lao Lun kebei to build a car for the festival to be completed. lianbu class set no. column temperature installation that is without notice axis research solid color fast anti-shi Lashi set dalon field weaving calendar flowers by seeking to pass the mouth broken condition mining fine gold industry products determination parameter layer end side clear to ten OK the book-writing factory must be away from the eyes of the sea, and the children of the qingcai certificate is lower than the eight test rules, near note to run the bumen iron should go to the county, the soldiers fixed in addition to the teeth like a thousand wins fine shadows ji bai Ge effect push blank configuration knife leaf rate today selected yangde phone query difference half enemy starting film Shi Xiang huaxu standby name red continuous average drug mark difficult to store tester body tight liquid accurate Jin Jiao wei weiban Xu broke the technology to eliminate the Bottom Bed field trend sense to Shen benhe village structure photo volume not engaged in sub-grinding fire section calculation according to the value of the United States Huang yibiao service early shift Mai cut letter row sound the attacker Zhang mi harm Hou Cao he shufa following the right city strict diameter screw detection left page anti su Xian bitter English fast said bad migration of barabai province black Wu Pei he di only pin how to plant Jing Zhu shengwang eye she grasp containing seedlings sub-Miscellaneous talk about food shot source examples caused by acid old but enough short drag agent Xuan Ring falls first ruler wave Bearing Powder jianfu fish with the test engraved rely on enough full husband loss bag promote branch bureau bacteria rod week Yan teacher to pick Qu chunyuan ultra negative sand seal for too model poor reduction Yang Jiang analysis Mu Yan ball Chao medical school gu death poison circle Wei Season Training Control exciting look called cloud mutual split grain mother trainer plug steel top policy double stay mistaken Foundation suck resistance so inch shield late silk female powder Welding Power Plants pro Hospital cold hit wrong scattered business video art destroy version Strong Room Light blood times lack of PCT pump check absolutely rich City Chong spray soil simple no column Li wangpan magnetic Xiong like sleepy Yi Zhou off cast to slave side Run cover the swing from the touch xingsong to get xingdu official mixed Ji according to not burst frame Wide winter seal wet partial grain eat hold valve mine village responsibility cooked stable hard price nu turn Qijia pre-job evaluation read back co-loss cotton invasion of gray although the spear thick Luo mud open the egg box ops oxygen love stopped once dissolved camp final gang Meng Qian to do Russia to shrink sand back Chen Fen machinery carrying young which strip, force, spin, sign, slot, hold, bear, fresh, card, drill, weak, foot, fear, salt, Yin, Feng, edit, print, Bee, Rush, escape, search, vibration, run, Yang, Wu, domain, very fast different sequence free paper night township JIU licylinder folder Nian LAN Ying Gou Yi Ru kill steam phosphorus Jing plug Yi huan iron fill yi ya Wing Wa tilting Array Carbon play Wei Fu ya Yong tile oblique irrigation ou Xian shun pig foreign rot please pass the division of dangerous pulse should laugh if the tail bunch of strong and violent enterprises food Sui Chu Han more green drag ox copy dyeing autumn round forging Yu Xia treatment tip colony jing Fei Zhou visits blowing Rong copper along the rolling passenger call drought Wu Zhi nancu Piao Tibet dare to make Gap shell sulfur coal yingzhu stick probe thin late shanfu longitudinal selection ceremony may Fu residual mine yan sentence pure gradual cultivation run ze slow planting Lu chifan environment tide off cone Xi Chi defeat ship false Bright said to the gang Zhe Huai cut the tribute was strong financial instrument sinning Ma sin zuxi car wear goods sales Qi rat pumping painting feeding longku shouzhu house Song Han Xi brother wash eclipse waste na belly almost recording mirror women evil fat village wipe risk likes Bell shake the handle debate zhugu sell chaos virtual bridge Obo catch the way of the amount of the wall network cut wild left quiet seek to get the hanging class town arrogant Sheng aid Zha worry key Fu Qing together around the moo Busy dance met suo Gu Jiao yanghu dingtalk renyin trace broken stretch lamp to avoid Pan death answer Yong frequency Huang Liu ha uncover ganuo summary Xian concentrated island attack who Hong Xie gun pouring spot news understand spirit egg closed children release milk giant private yin Yi Jing tan tired Yun Mo dulle Bending Performance recruit Shao Hu call pain peak 0 Chai spring Wu jump Ju Shang Ding Qin slightly chasing Liang discount alkali shugang dig blade drama hehe chest heng Qin film published in the case of slow and convex active cut Sichuan snow chain Yu la face households Luo shu Bo Meng buy Yang zongjiao saqi filter silicon carbon shares sitting Steam Condensate actually trapped gun Li rescue hidden Holes criminal tube you song arc burst paradox tu flavor Jin arm barrier brown Lu Jian Zun bean pull Mo against Sanpo sewing police pick dirty ice Cambodia mouth what rice plastic sent Zhao shout mat Kang zumu was Frame garden cavity order fragrant meat younger brother house min Hui forget clothing Sun Ling lie Hugh borrow Dan du ear planing tiger pen thin Kun Lang SA tea drop showner cave covered Lun Niang tons dip sleeve beads female mom zixi tower hammer shock years old appearance clean split prison front suspected Ba flash Po fierce v brush malicious and disaster recovery noisy Qiao Tang leak smell Shen Rong chlorine waste stem man where grab like pulp beside Bo also loyal sing mengyu to catch the lock, especially by the Wuzhi light allow rebellion animal capture touch rust sweep bibao core ye Jian secret Jing Jiang calcium shoulder Teng dry throwing rail Hall mix dad follow the temptation to liken liquor rope poor pond dry Bubble bag long feed aluminum soft canal used trade dung integrated wall tends to be another ink congestion Qi reverse unload air fog crown C Street laibei spoke sausage Fu Ji xiaorui stunned squeeze seconds to overhead Mu rotten Sen sugar Sheng wa Tao word late silkworm hundred million moment ";
$ ImgWidth = 140;
$ ImgHeight = 40;
$ Authimg = imagecreate ($ imgWidth, $ imgHeight );
$ BgColor = ImageColorAllocate ($ authentication, 255,255,255 );
$ Fontfile = "heiti. ttf ";
$ White = imagecolorallocate ($ authimg, 234,185, 95 );
Imagearc ($ authimg, 150, 8, 20, 20, 75,170, $ white );
Imagearc ($ authimg, 180, 75,175, 30, $ white );
Imageline ($ authimg, 20, 20, 180,30, $ white );
Imageline ($ authimg, 20, 18, 170,50, $ white );
Imageline ($ authimg, 25, 50, 80, 50, $ white );
$ Noise_num = 800;
$ Line_num = 20;
Imagecolorallocate ($ authimg, 0xff, 0xff, 0xff );
$ Rectangle_color = imagecolorallocate ($ authimg, 0xAA, 0xAA, 0xAA );
$ Noise_color = imagecolorallocate ($ authimg, 0x00,0x00,0x00 );
$ Font_color = imagecolorallocate ($ authimg, 0x00,0x00,0x00 );
$ Line_color = imagecolorallocate ($ authimg, 0x00,0x00,0x00 );
For ($ I = 0; $ I <$ noise_num; $ I ++ ){
Imagesetpixel ($ authimg, mt_rand (0, $ imgWidth), mt_rand (0, $ imgHeight), $ noise_color );
For ($ I = 0; $ I <$ line_num; $ I ++ ){
Imageline ($ authimg, mt_rand (0, $ imgWidth), mt_rand (0, $ imgHeight), mt_rand (0, $ imgWidth), mt_rand (0, $ imgHeight ), $ line_color );
$ Randnum = rand (0, strlen ($ str)-4 );
If ($ randnum % 2) $ randnum + = 1;
$ Str = substr ($ str, $ randnum, 8 );
$ Str = iconv ("GB2312", "UTF-8", $ str );
ImageTTFText ($ authimg, 20, 0, 16, 30, $ font_color, $ fontfile, $ str );
ImagePNG ($ authimg );
ImageDestroy ($ authimg );

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: 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.