PHP Generate Verification Code

Source: Internet
Author: User
Tags border color

code.php:

1<?PHP2     //Verification Code Production3 //File header ...4     Header("Content-type:image/png"); 5     //Create True Color white paper6     $im= @imagecreatetruecolor (.) or die("Build image Failed"); 7     //Get background color8     $background _color= Imagecolorallocate ($im, 255, 255, 255); 9     //Fill the background color (this thing is like oil barrels)TenImagefill ($im, 0, 0,$background _color);  One     //Get Border color A     $border _color= Imagecolorallocate ($im, 200,200,200);  -     //Draw Rectangle, border color 200,200,200 -Imagerectangle ($im, 0,0,49,19,$border _color);  the  -     //line up background, full screen with 1 or 0 -      for($i= 2;$i<18;$i++){  -         //get random tint +         $line _color= Imagecolorallocate ($im,Rand(200,255),Rand(200,255),Rand(200,255));  -         //Draw Line +Imageline ($im, 2,$i, 47,$i,$line _color);  A     }  at  -     //Set Font size -     $font _size=12;  -  -     //set up the printed text -     $Str[0] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  in     $Str[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  -     $Str[2] = "01234567891234567890123456";  to  +     //get a 1th random text -     $imstr[0] ["s"] =$Str[Rand(0,2)] [Rand(0,25)];  the     $imstr[0] ["x"] =Rand(2,5);  *     $imstr[0] ["y"] =Rand(1,4);  $ Panax Notoginseng     //get a 2nd random text -     $imstr[1] ["s"] =$Str[Rand(0,2)] [Rand(0,25)];  the     $imstr[1] ["x"] =$imstr[0] ["X"]+$font _size-1+Rand(0,1);  +     $imstr[1] ["y"] =Rand(1,3);  A  the     //get a 3rd random text +     $imstr[2] ["s"] =$Str[Rand(0,2)] [Rand(0,25)];  -     $imstr[2] ["x"] =$imstr[1] ["X"]+$font _size-1+Rand(0,1);  $     $imstr[2] ["y"] =Rand(1,4);  $  -     //get a 4th random text -     $imstr[3] ["s"] =$Str[Rand(0,2)] [Rand(0,25)];  the     $imstr[3] ["x"] =$imstr[2] ["X"]+$font _size-1+Rand(0,1);  -     $imstr[3] ["y"] =Rand(1,3); Wuyi  the     //Write random string -      for($i= 0;$i<4;$i++){  Wu         //get a random darker color -         $text _color= Imagecolorallocate ($im,Rand(50,180),Rand(50,180),Rand(50,180));  About         //Drawing Text $Imagechar ($im,$font _size,$imstr[$i["X"],$imstr[$i["Y"],$imstr[$i["s"],$text _color);  -     }  -  -     //Show Pictures AImagepng ($im);  +     //Destroying pictures theImagedestroy ($im);  -?>

HTML to invoke:

1 <HTML>2 <Head>3 <title>Example of picture verification</title>4 <styletype= "Text/css">5 </style>6 </Head> 7 <Body>8 <formID= "Login"Action=""Method= "POST">9 <P>This example verifies that the instance</P>Ten <P> One <span>Verification Code:</span> A <inputtype= "text"name= "Validate"value=""size=10>  - <imgtitle= "Click to refresh"src= "code.php"></img> - </P> the <P> - <inputtype= "Submit"> - </P> - </form>

PHP Generate 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.