Modified a very good PHP verification code (support Chinese) _php tutorial

Source: Internet
Author: User
Tags php class
PHP English Verification Code
Copy CodeThe 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 a picture
$this->createimg ();
Setting interference elements
$this->setdisturb ();
Set the verification code
$this->setcaptcha ();
Output picture
$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)? : $area;
Join 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 arcs
for ($i = 0; $i <= 5; $i + +) {
$color = Imagecolorallocate ($this->im, rand (255), Rand (255), rand (100, 255));
Imagearc ($this->im, rand (0, $this->width), rand (0, $this->height), rand (+), rand (+),, $color) ;
Private Function Createcode ()
$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ";
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 (+), rand (128, 250));
$size = rand ($this-&GT;HEIGHT/5), Floor ($this-&GT;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!");

Copy CodeThe code is as follows:
Require_once ' captcha.class.php ';
$captcha = new Captcha (80,30,4);
$captcha->showimg ();

It is supported in English, and the script house is accompanied by a verification code that supports Chinese.
Copy CodeThe code is as follows:
Reprint please indicate from Itbbs.
Please contact the author email:
Header ("Content-type:image/png");
$str = " The first is in the big and the main person for the people on the labor to move to the domestic with me to he will be a sub-class on the level of the level of righteousness to the Ministry of the public can be out of the side of the peer said to grow a life of leather and many children after self-social plus small machine also through the power line of the high-volume long party to real home fixed deep method of water physical and chemical dispute is two from the Miyoshi 10 war, non-agricultural and other anti-body road map to the new opening of the knot in the first Things from when the two also gifted team, such as should shape want to make a heart-like dry all to change the point of fertility and the inner part of the cause of the day by the pressure of the members of the gas industry on behalf of the whole group number of fruit phase guide the basis or month Mao ran it's the most and the outside. Five solutions to the forest of the Mi Qun head meaning only Ming four Ma Wen Tong, but the bar and the male hole leader inflow into the seat of the EQ and fly crude oil put up the problem of quality refers to the establishment of the area to test the living people are very teaching Hereby, often stone strong soil less has root of the total alignment of the general type of conversion nine you take the west holding the total material re-election of the concept of seven, the mountain-pass hundred more see must be true to protect the Heat committee hand to the branch has been to repair the heath a few first avoid special what type six with an indication of the return of each east of the wind back to the south-canton of the north of the road to make a car to do business by the whole set number of Levin installed, namely, the unknown axis research monochrome solid-fast anti-Slavs set up the field weaving calendar Flowers by To find out the fault condition of mining fine gold boundary products to the boundary clearance to million accurate book operation factory must be away from the re-head of the sea-right vote children green only certificate of low cross-border eight test regulation of the near-to-the-gate iron need to go to the county soldiers solid removal of the same as the lead teeth thousand wins a brief review on the leaf rate of the white lattice effect of the fine shadow in the selection of the blade ratio of the current election to the second half of the enemy began to apply sound to the recovery of the name of the red continuation of the drug mark is difficult to keep the weight of the body tight liquid of the lower dimension plate of the reduction of the base bed field Potential end sense toward God he cun structure illumination capacity not to engage in the sub-mill Group fire Section calculation of the state-of-the-Huang clothing morning wheat cutting letter row station sound of the hit Su Zhangmi hou Cao He tree fertilizer in the right side of the city of the left page anti-su show bitter British fast called bad move about Pakistan Timber Province black Wuppe Hati only needle How to implant the King eye she grabbed the side of the seedling to talk about the source of the surrounding food injection of acid old but sufficient short-stroke Xuan fall The first ruler wave bearing powder to practice the fish with the test The Mitsuo is enough to lose the pack to promote the branch of the stem Zhou Yan Division Cuschun Ultra-negative sand seal change too mold poverty reduction Yangyangiang analysis mu wood words ball toward medical school ancient rice song listen to the only to lose slip station Another Wei drum just write Liu Weilio fan for a piece of work a set of friends to limit the rest of the roll of law rain let bone far to help the first skin broadcast gifted death poison Circle Wei Ti Xun control excited to call the cloud mutual crack grain masterbatch Female practice plug steel top strategy double left wrong base suction resistance so inch shield late silk woman loose welding gong Plant Pro-school cold and wrong scattered commercial visual arts and crafts out of the 0 room light blood times the lack of the pump observation of the urban Chong-tu-tu soil simply no column Li Huanpan magnetic male like trapped Shong off delivery slave side run cover swing from the touch star Pine to receive the independence of the official mixed Ji Yi the width of the winter chapter of the wet partial grain to eat and hold the valve mine village responsibility mature steady win hard price to turn odd a pre-vocational evaluation read Back association damage cotton invasion Ash although spear thick Luo mud to inform egg box palm oxygen loving stop once dissolve camp finally outline Meng money to be full of Russian shrinkage Sha Hui Chen to beg for the child of the force of the small stripping of the rotation of the groove down to hold it still ah fresh bar card coarse medium drill weak foot afraid of salt end Yin Feng Production Bee urgent take the expansion of flying dew nuclear margin Rang Central Wu-Hui, non-paper night township long scribe cylinder clip read LAN Anh Ditch b Confucianism kill vapor phosphorus difficult crystal plug the Flame Huan iron complement our Bud Yongwa Dip array Carbon show Wei tooth Bud Yong wa Oblique irrigation Eugeshun Pig Yang Rot please the meridian of the pulse should laugh if the tail of the strong and the enterprise dish Han and green tow cows dye both autumn and winter forge Jade Summer healing Kinguizhou visit blown Rong copper alongTo call for a roll of rain and the brain to take possession of the crack furnace shell sulfur coal ying casting adhesion to the good fortune of the Reyen of the residual smoke sentence pure gradual tillage run ze slow planting Rutch The tide cross-cut cone Hitch defeat ship false Bright said the Zhehwai cut the pendulum tribute to the Jin Cai Shen Lian ma sin ancestral car wear cargo pin Zimping draw feed Dragon Storehouse keep build room song Cold Xi elder brother wash eclipse waste na belly to record mirror women's fat zhuang rub risk praise clock shake the handle of Bamboo Valley sell chaos Bridge Austria Bo drive down the Wall network cross-section of the plot to hang up the course town of the Fu Qing of the anti-aid tie-in-the-hook to the So Gu gum yanghu nail benevolence sound trace broken extension lamp to avoid flooding death answer Yong Frequency Huang Liuha Jie Gannon almost the constitution of dense island who Honche cannon to the spot to understand the spirit of the egg closed children release milk giant private silver Ychintan tired mold Dulle isolation bending performance strokes Shaoxing hu call Pain Peak 0 Diesel Spring noon Jump Ju Shang Dingqin slightly chase beam depletion alkali post dug blade play heap Hittite Chest value of the film in the case of the paper seedling slow convex service shears Sichuan snow chain fishing face home Yang Zongjio to buy the flag filter silicon carbon stocks sit steam trap gun Li save take Dark Hole criminals you song arc blasting fallacy Tu Jin arm barrier brown land Ah Jian-zun bean pull mo thumper around seam police pick dirty ice Cambodian mouth what rice plastic send Zhao shout mat Kang The garden cavity order fragrant Meat Brother house sensitive to forget clothes Sun Ling Ridge cheat Hugh borrow Dan Watanabe planing Tiger pen dilute kun lang tea drip shallow hug cave cover LUN Niang ton dip sleeve beads Female mom purple play Tower Hammer earthquake old appearance clean cut the front of the fire, the Flash PO fierce and sudden disaster, Joe Tang leak smell shen melt chlorine waste stalk man who rob like Pulp beside the glass also loyal sing to catch lock, especially by Uzhi light tolerance rebel prisoner capture rust sweep Bilibao core ye Jian-jiang calcium shoulder teng withered throw rail Church mix dad lure 祝励 Ken wine rope Poor pond dry bubble bag long feeding aluminum soft channel of habitual trade manure wall trend of the anti-dumping air fog Crown Street Lai Pui-Spoke sausage-fu Ji infiltration rui-chi-hung the second suspension of Sam Rotten sugar Sheng-tao word late silkworm billion moment ";
$imgWidth = 140;
$imgHeight = 40;
$authimg = Imagecreate ($imgWidth, $imgHeight);
$bgColor = Imagecolorallocate ($authimg, 255,255,255);
$fontfile = "Heiti.ttf";
$white =imagecolorallocate ($authimg, 234,185,95);
Imagearc ($authimg, 8, A, A, $white);
Imagearc ($authimg, 7,50, 175, $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, 0, $font _color, $fontfile, $STR);
Imagepng ($AUTHIMG);
Imagedestroy ($AUTHIMG);
?> true techarticle PHP English Verification code captcha.class.php copy 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: 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.