PHP写的验证码_PHP教程

WBOY
发布: 2016-07-13 10:18:09
原创
929 人浏览过

PHP写的验证码

header('content-type:image/png');
$w = 200;
$h = 50;
$i = imagecreatetruecolor($w,$h);
$bgc = imagecolorallocate($i,251,251,251);
imagefill($i,0,0,$bgc);




function getStr($len = 4){
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$s = '';
for($i=0;$i $s.=$str{mt_rand(0,strlen($str)-1)};
}
return $s;
}
//$c = imagecolorallocate($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
//imagettftext($i,20,mt_rand(0,10),10,35,$c,'font/h.ttf',getStr(10));






$s = getStr(6);
for($n=0;$n $c = imagecolorallocate($i,mt_rand(0,155),mt_rand(0,155),mt_rand(0,155));
imagettftext($i,mt_rand(15,30),mt_rand(-15,30),10+($n*18),mt_rand(25,35),$c,'font/h.ttf',$s{$n});
}




$s = getStr(20);
for($n=0;$n $c = imagecolorallocatealpha($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255),50);
imagettftext($i,mt_rand(5,10),mt_rand(-15,30),mt_rand(0,$w),mt_rand(0,$h),$c,'font/h.ttf',$s{$n});
}




imagepng($i);
imagedestroy($i);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/885673.htmlTechArticlePHP写的验证码 header('content-type:image/png'); $w = 200; $h = 50; $i = imagecreatetruecolor($w,$h); $bgc = imagecolorallocate($i,251,251,251); imagefill($i,0,0,$bgc); functio...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!