PHP生成图形验证码(大小写字母与数字混合)
2018-07-20 来源:open-open
<?php
header("content-type:image/png");
$num = $_GET['num'];
$imagewidth=60;
$imageheight=18;
srand(microtime() * 100000);
$numimage = imagecreate($imagewidth,$imageheight);
imagecolorallocate($numimage,183,180,83);
for($i=0;$i<strlen($num);$i++){
$font = mt_rand(3,5);
$x = mt_rand(1,8)+$imagewidth*$i/4;
$y = mt_rand(1,$imageheight/3);
$color=imagecolorallocate($numimage,mt_rand(0,50),mt_rand(0,150),mt_rand(0,255));
imagestring($numimage,$font,$x,$y,$num[$i],$color);
}
imagepng($numimage);
imagedestroy($numimage);
?>
调用方法:
<?php
session_start();
include_once 'conn/conn.php';
$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
$num = null;
for($i = 0; $i < 4; $i++) {
$num .= $pattern{mt_rand(0, 61)};
}
?>
<div> 验证码:
<input id="lgchk" type="text" />
<img src="valcode.php?num=<?php echo $num; ?>" width="55" height="18" /> </div>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:python中的字典用法示例
最新资讯
热门推荐