PHP 绘制验证码

使用PHP绘制验证码  可直接使用

//   验证码
 <?php 

$checkCode = "";
for ($i=0; $i < 4; $i++) { 
    // 十进制转换为十六进制
    $checkCode.=dechex(rand(1,15));
}
//存入session
session_start();
$_SESSION['checkCode']=$checkCode;

//1创建画布
$img = imagecreatetruecolor(100, 30);
//颜色
$red = imagecolorallocate($img, 255, 255, 255);

//2画一行字符串  字体大小,坐标
imagestring($img, rand(1,5), rand(0,80), rand(0,20), $checkCode, $red);

//画干扰线
for ($i=0; $i < 20; $i++) { 
    //imageline(image, x1, y1, x2, y2, color)
    imageline($img, rand(0,100), rand(0,30), rand(0,100), rand(0,30), imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)));
}

//3输出到网页
header("content-type:image/png");
imagepng($img);

//4销毁
imagedestroy($img);

/************login.php**********/
/*
请输入验证码:
<img src="checkCode.php" onclick="this.src='checkCode.php?aa='+Math.random()" />
*/
 ?>
原文地址:https://www.cnblogs.com/zxf100/p/6736083.html