PHP snowflake background verification code examples

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

<?session_start();?> 
<FORM METHOD=POST ACTION=""> 
<input type=text name=number maxlength=4><img src="YanZhengMa.php?act=init"> 
<INPUT TYPE="submit" name="sub"> 
</FORM> 
<? 
//The inspection check code  
If (isset ($HTTP_POST_VARS["sub"])):  
If ($HTTP_POST_VARS["number"]  =  $HTTP_SESSION_VARS[login_check_number]  || !; empty ($HTTP_POST_VARS["number"])) { 
        echo  "check code is not correct!"    
}else{ 
        echo "verification code by! ";  

ENDIF;  
Show_source ('test.php' );
// the above the page source code


// the following is generated code source code 
show_source('YanZhengMa.php'); 
?>

Verification code:

<?php 
session_start(); 
session_register("login_check_number"); 
//See last night on chianren code effect, We consider the, With the PHP GD library fulfilled a similar function of  
// the first generation background, Then the generated verification code to the  
$img_height=120;         // the first define the picture of the length, the width of  
$img_width=40;  
If ($HTTP_GET_VARS["act"]==  "init { ");
        //srand (microtime) (  *  100000); //PHP420, Srand must not be  
        for ($Tmpa=0; $Tmpa<4; $Tmpa++) { 
                $nmsg.=dechex (rand (0,15));  
       }//by  sports98


        $HTTP_SESSION_VARS[login_check_number]  =  $nmsg;

        //$HTTP_SESSION_VARS[login_check_number]  =  strval (mt_rand ("1111", "9999"));         // generate 4 bit random number, In the session  
        // who can do under the supplementary, Can generate both letters and numbers?? - completed by sports98.

        $aimg  =  imageCreate ($img_height, $img_width);         // generated picture  
        ImageColorAllocate ($aimg,   255255255);                         // the picture color, ImageColorAllocate first define the color PHP that is the background color of the  
        $black  =  ImageColorAllocate ($aimg,   0,0,0);                 // definition need black  
        ImageRectangle ($aimg, 0,0, $img_height-1, $img_width-1, $black); // the first rectangular a black picture surrounded

        // the generation below snow background., In fact, is to generate some symbol   in the picture;
        for  ($i=1;   $i<=100;   $i++)   {        // the first with 100 test  
                imageString ($aimg, 1, mt_rand (1, $img_height), mt_rand (1, $img_width), "*", imageColorAllocate ($aimg, mt_rand (200255), mt_rand (200255), mt_rand (200255)));  
                // ha, See, In fact also not the snow, Is to generate * number. In order to make them appear to be ", 5 Color 6 color", You must in the 1 1 generation them, Let their position, color, Even the size of all the random number, Rand (or mt_rand) can be completed.  
       }

        // generated above the background, Now is the time to take a random number is generated on the. Truth and it almost, Random number 1 1 place, At the same time to make their location, size, colors are used as a random number ~~ 
        // in order to distinguish it from the background, Here the color does not exceed 200, The above is not less than 200 
        for  ($i=0; $i<strlen; $i++ ($HTTP_SESSION_VARS[login_check_number])) { 
                imageString ($aimg,   mt_rand (3,5), $i*$img_height/4+mt_rand (1,10), mt_rand (1, $img_width/2),   $HTTP_SESSION_VARS[login_check_number][$i], imageColorAllocate ($aimg, mt_rand (0100), mt_rand (0150), mt_rand (0200)));  
       } 
        Header ("Content-type:  image/png");         // tells the browser, The following data., Not according to   text display;
        ImagePng ($aimg);                                         // PNG format.  
    ImageDestroy($aimg); 
}
?>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Cindy at October 27, 2013 - 8:24 PM