24 Bridge Ming Moonlight 24

Source: Internet
Author: User
Tags ming
Verification code in the form implementation more and more, but with JS write verification code, always feel inconvenient, so learned the next PHP implementation of the verification code.

Well, there is nothing to do, but do not want to waste time, so learned the next PHP implementation verification code. It is the so-called, multi-technology does not pressure body. Also, it can be encapsulated into a function, which is also convenient for later use, but is not encapsulated now.

Now, let's talk about simple, pure digital verification codes.

For beginners, it is recommended to follow the comments //numbers of my Code . The simplest way to do this is to copy the entire code away.

Create a new captcha.php:

 Php//10> Set session, must be at the top of the scriptSession_Start(); $image= Imagecreatetruecolor (100, 30);//1> set captcha picture size function//5> set CAPTCHA color imagecolorallocate (int im, int red, int green, int blue);$bgcolor= Imagecolorallocate ($image, 255,255,255);//#ffffff//6> area is populated with an int imagefill (int im, int x, int y, int col) (x and Y) where the area is shaded, and col represents the color to be paintedImagefill ($image, 0, 0,$bgcolor); //10> Setting Variables$captcha _code= ""; //7> generating random numbers for($i= 0;$i<4;$i++){        //Set Font size$fontsize= 6; //set Font color, random color$fontcolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120));//0-120 Dark Color//Set number$fontcontent=Rand(0,9); //10>.= Continuous definition variables$captcha _code.=$fontcontent; //Set coordinates$x= ($i*100/4) +Rand(5,10); $y=Rand(5,10); Imagestring ($image,$fontsize,$x,$y,$fontcontent,$fontcolor); }    //10> Save to session$_session[' authcode '] =$captcha _code; //8> Add interference elements, set snowflake dots for($i= 0;$i<200;$i++){        //set the color of the point, 50-200 color is lighter than the number, do not disturb reading$pointcolor= Imagecolorallocate ($image,Rand(50,200),Rand(50,200),Rand(50,200)); //imagesetpixel-draw a single pixelImagesetpixel ($image,Rand(1,99),Rand(1,29),$pointcolor); }    //9> Add interference element, set horizontal line for($i= 0;$i<4;$i++){        //set the color of a line$linecolor= Imagecolorallocate ($image,Rand(80,220),Rand(80,220),Rand(80,220)); //set line, 2.1-wireImageline ($image,Rand(1,99),Rand(1,29),Rand(1,99),Rand(1,29),$linecolor); }    //2> set head, Image/pngHeader(' Content-type:image/png '); //3>imagepng () Creating PNG graphics functionsImagepng ($image); //4>imagedestroy () End graph function Destroy $imageImagedestroy ($image);

Then there is the code for the static page: index.html

  DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Confirm Verification Code
   title>
    Head><Body><formMethod= "POST"Action= "./form.php"><P>Verification Code:<imgID= "Captcha_img"Border= ' 1 'src= './captcha.php?r=
     echo rand ();?>'/><ahref= "javascript:void (0)"onclick= "document.getElementById (' captcha_img '). src= './captcha.php?r= ' +math.random ()">A change? 
        a> 
         p><p> Please enter the verification code: < input type = "text" name = ' Authcode ' value ='' /> 
          P > < P >< input type = ' Submit ' value = ' Submit ' style = ' padding:6px 5px; ' /> 
           P >  
            body> 
             html>      

From index.html you can see that the submitted form is to form.php, so there is a form.php code to judge:

 
  PHP    Header("Content-type:text/html;charset=utf-8");            // Set Header information    //isset () detects if the variable is set if(isset($_request[' Authcode '])) {         session_start();         // strtolower () lowercase function if (strtolower($_request$_session[' Authcode ']) {            // Jump Page Echo "";        } Else {            // hint and jump page echo "";        }         Exit ();    }

The display page is as follows:

So, the realization of pure numbers, the number of English should not be difficult. The code to be modified is only modified by captcha.php //7> generate random numbers to //7> generate random letters and numbers , If you are really cute to modify these words to think can be achieved, then congratulate you, you always keep happy. Children with brain residue are much more happy.

Don't say much nonsense, pull the code.

 Php//10> Set session, must be at the top of the scriptSession_Start(); $image= Imagecreatetruecolor (100, 30);//1> set captcha picture size function//5> set CAPTCHA color imagecolorallocate (int im, int red, int green, int blue);$bgcolor= Imagecolorallocate ($image, 255,255,255);//#ffffff//6> area is populated with an int imagefill (int im, int x, int y, int col) (x and Y) where the area is shaded, and col represents the color to be paintedImagefill ($image, 0, 0,$bgcolor); //10> Setting Variables$captcha _code= ""; //7> generate random letters and numbers for($i= 0;$i<4;$i++){        //Set Font size$fontsize= 8; //set Font color, random color$fontcolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120));//0-120 Dark Color//Set the values that need to be randomly taken to remove error-prone values such as 0 and O$data= ' abcdefghigkmnpqrstuvwxy3456789 '; //Fetch value, String intercept method strlen get string length$fontcontent=substr($data,Rand(0,strlen($data)), 1); //10>.= Continuous definition variables$captcha _code.=$fontcontent; //Set coordinates$x= ($i*100/4) +Rand(5,10); $y=Rand(5,10); Imagestring ($image,$fontsize,$x,$y,$fontcontent,$fontcolor); }    //10> Save to session$_session[' authcode '] =$captcha _code; //8> Add interference elements, set snowflake dots for($i= 0;$i<200;$i++){        //set the color of the point, 50-200 color is lighter than the number, do not disturb reading$pointcolor= Imagecolorallocate ($image,Rand(50,200),Rand(50,200),Rand(50,200)); //imagesetpixel-draw a single pixelImagesetpixel ($image,Rand(1,99),Rand(1,29),$pointcolor); }    //9> Add interference element, set horizontal line for($i= 0;$i<4;$i++){        //set the color of a line$linecolor= Imagecolorallocate ($image,Rand(80,220),Rand(80,220),Rand(80,220)); //set line, 2.1-wireImageline ($image,Rand(1,99),Rand(1,29),Rand(1,99),Rand(1,29),$linecolor); }    //2> set head, Image/pngHeader(' Content-type:image/png '); //3>imagepng () Creating PNG graphics functionsImagepng ($image); //4>imagedestroy () End graph function Destroy $imageImagedestroy ($image);

The other two pages are not allowed to be modified.

In general, it is enough for now. But like the anime, there will always be a pan-out.

Well, let's take a Chinese character out of the pan. In fact, I am also ready to put the verification of Chinese characters into my graduation design, although now very popular sliding verification code, but I am not specifically learning JS.

Moreover, can also and the reply teacher said, our verification code does not need the material, even the picture also produces, uses own knowledge to install 13, also has not set.

 Php//11> Set session, must be at the top of the scriptSession_Start(); //1> function to set captcha picture size$image= Imagecreatetruecolor (200, 60); //5> Set the captcha color imagecolorallocate (int im, int red, int green, int blue);$bgcolor= Imagecolorallocate ($image, 255,255,255);//#ffffff//6> area is populated with an int imagefill (int im, int x, int y, int col) (x and Y) where the area is shaded, and col represents the color to be paintedImagefill ($image, 0, 0,$bgcolor); //7> Setting TTF fonts$fontface= ' FZYTK. TTF '; //7> set up the font to achieve a simple digital reserve$str= ' heaven and earth are unkind to all things for the dog Saints unkind to the people for the dog this often appears in the accusation of tyranny and brutality, and the cruelty of all things as a lowly pig dog to see and those high above the so-called Saints are not the same as the common people also as pigs and dogs as a thing but is taking the interpretation is not emotional proven itself to all things equal saints not emotional proven itself The common people of the hands of the children and the son of the old when the hero is looking at each other said a sentence holding the hand and son old woman tears hazy shy back to a nasty such plot we have not seen a lot but let's take a look at the original sentence of the sentence of the death of the alive said that the hands of the son and son grow old in sigh not I live Yu Ying XI No I believe it means that the warrior between Agreed to die together now and I have agreed to the people are gone how do I live ah naked brothers Friendship, describe a good base of friends than the love between men and women to fit a lot of it; //str_split () cut string as an array, one Chinese in utf_8 is 3 characters$strdb=Str_split($str, 3); //>11$captcha _code= ''; //8> generation of random men for($i= 0;$i<4;$i++){        //set Font color, random color$fontcolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120));//0-120 Dark Color//randomly selected Chinese$in=Rand(0,Count($strdb)); $CN=$strdb[$in]; //record the Chinese in a string that will be saved to the session$captcha _code.=$CN; /*Imagettftext (Resource $image, float $size, float $angle, int $x, int $y, int $color, String $fontfile, String $ Text) curtains, dimensions, angles, coordinates, colors, font paths, text strings Mt_rand () generate better random numbers, four times times faster than Rand ()*/Imagettftext ($image,Mt_rand(20,24),Mt_rand( -60,60), (40*$i+20),Mt_rand(30,35),$fontcolor,$fontface,$CN); }    //11> Save to session$_session[' authcode '] =$captcha _code; //9> Add interference element, set point for($i= 0;$i<200;$i++){        //set the color of the point, 50-200 color is lighter than the number, do not disturb reading$pointcolor= Imagecolorallocate ($image,Rand(50,200),Rand(50,200),Rand(50,200)); //imagesetpixel-draw a single pixelImagesetpixel ($image,Rand(1,199),Rand(1,59),$pointcolor); }    //10> Add interference element, set line for($i= 0;$i<4;$i++){        //set the color of a line$linecolor= Imagecolorallocate ($image,Rand(80,220),Rand(80,220),Rand(80,220)); //set line, 2.1-wireImageline ($image,Rand(1,199),Rand(1,59),Rand(1,199),Rand(1,59),$linecolor); }    //2> set head, Image/pngHeader(' Content-type:image/png '); //3>imagepng () Creating PNG graphics functionsImagepng ($image); //4>imagedestroy () End graph function Destroy $imageImagedestroy ($image);

Other pages also do not need to be modified.

As follows:

The above describes the 24 bridge Ming Moonlight 24, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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