php-验证码


<
html> <body> <h2>用户注册:</h2> <br> <form action="a.php" method="post">&nbsp;&nbsp;号:<input type="text" name="zh" id=""> <br>&nbsp;&nbsp;码:<input type="password" name="mm" id=""> <br> 验证码:<input type="text"name="yzm"> <br> <img src="yzm.php"> <br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html>

//html页面

 

 

 

<?php

    
    $a = imagecreatetruecolor(100,20);
    //画布
    
    $black = imagecolorallocate($a,0,0,0);
    $white = imagecolorallocate($a,255,255,255);
    $gray = imagecolorallocate($a,200,200,200);
    $red = imagecolorallocate($a,255,0,0);
    //颜料
    
    imagefill($a,0,0,$red);
    //填充
    
    for($i=0;$i<20;$i++){
    $x = mt_rand(0,100);
    $y = mt_rand(0,20);        
    imagesetpixel($a,$x,$y,$white);
    imagesetpixel($a,$x,$y+1,$white);
    imagesetpixel($a,$x,$y+2,$white);
    imagesetpixel($a,$x,$y-1,$white);
    imagesetpixel($a,$x,$y-2,$white);
    imagesetpixel($a,$x+1,$y,$white);
    imagesetpixel($a,$x+2,$y,$white);
    imagesetpixel($a,$x-1,$y,$white);
    imagesetpixel($a,$x-2,$y,$white);
    }

    $z1 = range('a','z');
    $z2 = range('A','Z');
    $z3 = mt_rand(0,9);
    $z4 = mt_rand(0,9);


    
    imagestring($a,26,25,2,$z1[mt_rand(0,24)],$white);
    imagestring($a,26,33,2,$z2[mt_rand(0,24)],$white);
    imagestring($a,26,41,2,$z3,$white);
    imagestring($a,26,49,2,$z4,$white);
    

    
    header("content-type:image/jpeg");
    imagepng($a);
    //保存
    
    imagejpeg($a);
    //输出


    

    
?>

//php画库

 

posted on 2017-03-19 22:00  加号与剑豪  阅读(89)  评论(0编辑  收藏  举报

导航