生成图片
vCode.php
<?php
header('Content-type:image/jpeg');
$width=120;
$height=50;
$str = "";
for($i=0;$i<5;$i++){
$str.=chr(rand(97,122));setcookie("vcode",$str);}
//创建图像
$img = @imagecreatetruecolor($width,$height);
//绘制图像
$colorBg = imagecolorallocate($img,rand(200,255),rand(200,255),rand(220,255));//背景颜色
$colorBorder = imagecolorallocate($img,0,0,0);//边框颜色
$colorStr=imagecolorallocate($img,rand(10,140),rand(10,150),rand(20,160));//字符串颜色
imagefill($img,0,0,$colorBg);//填充背景
imagerectangle($img,0,0,$width-1,$height-1,$colorBorder);//花边框
for($i=0;$i<100;$i++){//生成像素点
imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100)));}
for($i=0;$i<3;$i++){//三条横线
imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100)));}
imagettftext($img,14,rand(-5,5),rand(5,15),rand(30,35),$colorStr,'font/destroy.woff.ttf',$str);
//输出图像
imagejpeg($img);
//销毁图像
imagedestroy($img);
?>
注册信息存入Mysql数据库中
生成验证码图片
头像上传到mysql数据库
登录与mysql信息匹配
编写留言板