关于冰盾 | 使用条款 | 网站地图
 
php验证码
php验证码
作者:冰盾防火墙 网站:www.bingdun.com 日期:2014-12-03
 
<? 
/**
 * 验证码
 * 2011/8/21
 * kcj
 * */ 
include "isLogin.php"; 
//随机生成一个4位数字的验证码  
$num=''; 
for($i=0;$i<4;$i++){ 
    $num.=dechex(rand(0,20));  //dechex函数是十进制转会二进制  

session_start();   //开启session  
$_SESSION['yanzheng']=$num;  //用session记住这个验证数字  
header("Content-type:image/PNG"); 
$im=imagecreate(60,20);  //创建一个画布  
$back=imagecolorallocate($im,rand(0,55),rand(0,20),rand(0,5));//创建一个背景颜色 (黑色)  
$gray=imagecolorallocate($im,rand(0,255),rand(0,200),rand(0,55)); //(白色)  
imagefill($im,0,0,$gray);   //填充颜色  
$style=array($back,$back,$back,$back,$back,$gray,$gray,$gray,$gray,$gray); //生成数组  
imagesetstyle($im,$style);    //设定画线风格  
$y1=rand(0,20); 
$y2=rand(0,20); 
$y3=rand(0,20); 
$y4=rand(0,20); 
imageline($im,0,$y1,60,$y3,IMG_COLOR_STYLED);     //画一条线  
imageline($im,0,$y2,60,$y4,IMG_COLOR_STYLED); 
//在画布上随机生成大量黑点,起干扰作用  
for ($i=0;$i<80;$i++){ 
    imagesetpixel($im,rand(0,60),rand(0,20),$back); 

$str=rand(3,8); 
for ($i=0;$i<4;$i++){ 
    $strp=rand(1,6); 
    imagestring($im,6,$str,$strp,substr($num,$i,1),$back); 
    $str+=rand(8,12); 

ImagePNG($im); 
imagedestroy($im); 
 
?> 

摘自 chaojie2009的专栏
 

 
最新内容:
PHP生成静态页面详解[2014-12-03]
Php部分常见问题总结[2014-12-03]
PHP和正则表达式[2014-12-03]
PHP技巧--通过COM使用ADODB[2014-12-03]
浅谈PHP+MYSQL身份验证的方法[2014-12-03]
七个诀窍帮你抵御DDoS攻击[2014-12-03]
相关内容:

合作伙伴: 黑基网 补天科技 威盾科技 站长下载 新飞金信 北京电信 ZOL应用下载
中华人民共和国增值电信业务经营许可证京ICP备14024464 公安备案号 京1081234 
版权所有©2003-2014 冰盾防火墙  www.BingDun.com 法律声明
总机:(010)51661195