<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户登录</title>
</head>
<body background="../c4d4e0dce3b544b58443019a511f51f0.jpg" style="background-size: 100% 100%;background-attachment: fixed;">
<div class="box">
<div class="title">用户登录</div>
<form action="../login.php" method="post">
<table class="login">
<tr><th>用户名:</th><td><input type="text" name="username" /></td></tr>
<tr><th>密码:</th><td><input type="password" name="password" /></td></tr>
<tr><th>验证码:</th><td><input type="text" name="captcha" /></td></tr>
<tr><th></th><td><img src="../view/code.php" /></td></tr>
<tr><th></th><td><input type="submit" value="登录"/><a href="register.php"><input type="button" value="前往注册"></a></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
//创建验证码
//验证码画布
$img_w = 100;
$img_h = 30;
$img = imagecreatetruecolor($img_w, $img_h); //创建画布
$bg_color = imagecolorallocate($img,0xcc,0xcc,0xcc); //画布颜色
imagefill($img,0,0,$bg_color); //背景色
//生成验证码文本
$count = 4;
$charset = 'ABCDEFGHIJKLMNOBQRXTUVWXYZ23456789'; //随机数
$charset_len = strlen($charset) -1; //随机数长度
$code=''; //保存生成的验证码
for ($i = 0; $i < $count; ++$i) {
//通过索引取出字符 mt_rand()用于获取指定范围内的随机数
$code .= $charset[mt_rand(0, $charset_len)];
}
//将生成的文本保存到session
session_start(); //启动session
$_SESSION['$capcha'] = $code;
//在画布中生成验证码文本
$fontsize = 16; //文字大小
$fontstyle = 'C:\Windows\Fonts\PRISTINA.TTF'; //字体样式
//指定长度的验证码
for($i=0; $i<$sount; ++$i) {
//随机生成字体颜色
$fontcolor = imagecolorallocate($img,mt_rand(0,100),mt_rand(0,50),mt_rand(0,255));
imagettftext(
$img, //画布资源
$fontsize, //文字大小
mt_rand(0,20) - mt_rand(0,25), //随机设置文字倾斜角度
$fontsize*$i+20,mt_rand($img_h,$img_w), //随机设置文字坐标,并自动计算间距
$fontcolor, //字体颜色
$fontstyle, //文字字体
$code[$i] //文字内容
);
}
//为验证码图片生成彩色噪点
for($i=0; $i<300; ++$i){
//随机生成颜色
$color=imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
//绘制随机干扰点
imagesetpixel($img,mt_rand(0,$img_w),mt_rand(0,$img_h),$color);
}
//绘制干扰线
for($i=0; $i<10;++$i){
//随机生成干扰线颜色
$color = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
//随机绘制干扰线
imageline($img,mt_rand(0,$img_w),0,mt_rand(0,$img_h*5),$img_h,$color);
}
header('content-Type: image/gif'); //输出图像
imagegif($img);
有大佬知道吗