Random Verification Code

Source: Internet
Author: User

1<?PHP2 3     $type=1;4     $len=4;5     Header("Content-type:image/png");6     //test function7 Newcode ();8     9     functionNewcode ($type=1,$len=4){Ten          One         //Verification Code Content A         $str= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -          -         if($type==1){ the             $m=9; -}ElseIf($type==2){ -             $m=35; -}Else{ +             $m=61; -         } +         $code=""; A          for($i= 0;$i<$len;$i++){ at             $code.=$str[Rand(0,$m)];//Random Get Verification code -         } -     //Create a canvas -     $im=imagecreatetruecolor (50*$len, 50); -     //creating brushes and backgrounds -     $BG=imagecolorallocate ($im, 230,230,230); in     $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); -     //Background Fill toImagefill ($im, 0, 0,$BG); +     //add a random color to the noise point -      for($i= 0;$i<50*$len;$i++){ the         $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); *Imagesetpixel ($im,Rand(0,50*$len),Rand(0,50),$HB); $     }Panax Notoginseng     //adding random interference lines -      for($i= 0;$i<$len;$i++){ the         $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); +Imageline ($im,Rand(0,50*$len),Rand(0,50),Rand(0,50*$len),Rand(0,50),$HB); A     } the     //Add Verification Code +      for($i= 0;$i<$len;$i++){ -         $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); $Imagettftext ($im, 40,Rand( -30,30), 20+40*$i, 44,$HB, "Msyh.ttf",$code[$i]); $     } -     //Output Verification Code -Imagepng ($im); the     //Freeing Resources -Imagedestroy ($im);Wuyi  the      -     } Wu  -  About?>

Random Verification Code

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.