Modified a very good php verification code (supporting Chinese characters) _ PHP Tutorial

Source: Internet
Author: User
Modified a very good php verification code (supporting Chinese ). Php captcha. class. php copy code :? PhpclassCaptcha {private $ width; private $ height; private $ codeNum; private $ code; private $ im; function _ const Php verification code
Captcha. class. php

The code is as follows:


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

The code is as follows:


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.

The code is as follows:


/*
For more information, see ITBBS.
Modify contact author mailbox: Smartly@itbbs.cn
*/
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 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 );
?>

The captcha. class. php code is as follows :? Php class Captcha {private $ width; private $ height; private $ codeNum; private $ code; private $ im; function _ const...

Related Article

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.