pull/18/head 2.4.6
icret 2022-01-21 22:25:10 +08:00
parent 8785e2ce50
commit 36251d5230
2 changed files with 15 additions and 20 deletions

View File

@ -9,42 +9,41 @@ $bgcolor = imagecolorallocate($image, 255, 255, 255); //验证码颜色RGB为(25
imagefill($image, 0, 0, $bgcolor); //区域填充
$cap_code = "";
for($i=0;$i<4;$i++){
for ($i = 0; $i < 4; $i++) {
$fontsize = 12; //设置字体大小
$fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
$fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
//数字越大颜色越浅这里是深颜色0-120
$data = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890'; //添加字符串
$fontcontent = substr($data, rand(0,strlen($data)),1); //去除值,字符串截取方法
$cap_code.=$fontcontent; //.=连续定义变量
$x = ($i*150/4)+rand(5,10);
$y = rand(5,10);
$fontcontent = substr($data, rand(0, strlen($data)), 1); //去除值,字符串截取方法
$cap_code .= $fontcontent; //.=连续定义变量
$x = ($i * 150 / 4) + rand(5, 10);
$y = rand(5, 10);
//设置坐标
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
$_SESSION['code'] = $cap_code; //存到session
//设置干扰元素,设置雪花点
for($i=0;$i<300;$i++){
$inputcolor = imagecolorallocate($image, rand(50,200), rand(20,200), rand(50,200));
for ($i = 0; $i < 300; $i++) {
$inputcolor = imagecolorallocate($image, rand(50, 200), rand(20, 200), rand(50, 200));
//设置颜色20-200颜色比数字浅不干扰阅读
imagesetpixel($image, rand(1,149), rand(1,39), $inputcolor);
imagesetpixel($image, rand(1, 149), rand(1, 39), $inputcolor);
//画一个单一像素的元素
}
//增加干扰元素,设置横线(先设置线的颜色,在设置横线)
for ($i=0;$i<4;$i++) {
$linecolor = imagecolorallocate($image, rand(20,220), rand(20,220),rand(20,220));
for ($i = 0; $i < 4; $i++) {
$linecolor = imagecolorallocate($image, rand(20, 220), rand(20, 220), rand(20, 220));
//设置线的颜色
imageline($image, rand(1,149), rand(1,39), rand(1,299), rand(1,149), $linecolor);
imageline($image, rand(1, 149), rand(1, 39), rand(1, 299), rand(1, 149), $linecolor);
}
//因为有些浏览器访问的content-type会是文本型所以我们需要设置成图片的格式类型
header('Content-Type:image/png');
imagepng($image); //建立png函数
imagedestroy($image);
imagedestroy($image);

View File

@ -48,7 +48,6 @@ if (isset($_REQUEST['code'])) {
</script>';
}
}
?>
<form class="form-horizontal" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" onsubmit="return md5_post()">
<div class="form-group">
@ -72,7 +71,6 @@ if (isset($_REQUEST['code'])) {
<input class="form-control" type="text" name="code" value="" placeholder="请输入上方4位数验证码 - 注意大小写" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
@ -88,7 +86,6 @@ if (isset($_REQUEST['code'])) {
</div>
</div>
</form>
<script src="<?php static_cdn(); ?>/public/static/md5.min.js"></script>
<script>
function md5_post() {
@ -99,6 +96,5 @@ if (isset($_REQUEST['code'])) {
return true;
}
</script>
<?php
require_once APP_ROOT . '/application/footer.php';