zoukankan      html  css  js  c++  java
  • PHP验证码

    自己写了个简单的php验证码:

    <?php
    $img=ImageCreate(200,50);
    $background_color=ImageColorAllocate($img,255,255,255);
    $gray=ImageColorAllocate($img,255,0,0);
    //画点
    for($i=0;$i<100;$i++)
    {
    	$pointcolor=ImageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
    	ImageSetPixel($img,mt_rand(50,149),mt_rand(10,39),$pointcolor);
    }
    
    //划线
    for($k=0;$k<2;$k++)
    {
        $linecolor=ImageColorAllocate($img,mt_rand(0,255),255,mt_rand(0,255));
    	$sy=mt_rand(11,39);
    	$ey=mt_rand(11,39);
    	ImageLine($img,50,$sy,150,$ey,$linecolor);
    }
    
    //字符
    $pattern='1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    for($j=0;$j<4;$j++)
    {
    	$fontcolor=ImageColorAllocate($img,0,0,0);
    	$x=mt_rand(60,140);
    	$y=mt_rand(15,25);
    	$key=$pattern[mt_rand(0,62)];
    	ImageString($img,5,$x,$y,$key,$fontcolor);
    
    }
    
    //画矩形
     ImageRectangle($img,50,10,150,40,$gray);
     header('Content-Type:image/png');
    
     //生成图像
     ImagePNG($img);
     ImageDestroy($img);
    ?>
    

  • 相关阅读:
    python之路-javascript
    python之路-css
    python之路-初识前端
    python之路-线程
    python之路-socket
    base64 convert to file
    base64 json
    centos7 hostname
    geoip2 domain
    佛教六度
  • 原文地址:https://www.cnblogs.com/xshang/p/3495595.html
Copyright © 2011-2022 走看看