php实现图片算术数字计算运算验证码人机验证示例代码
代码语言:php
所属分类:验证码
代码描述:php实现图片算术数字计算运算验证码人机验证示例代码,增加了一些干扰线,但是ai还是能识别的。
代码标签: php 图片 算术 数字 运算 验证码 人机 验证 示例 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php
session_start();
class CaptchaHandler {
public function getCaptcha() {
return $this->verifycodebase64();
}
private function verifycodebase64() {
// 1. 临时画布尺寸(稍微大一点,防止扭曲时边缘被切掉)
$w = 140;
$h = 50;
// 创建临时画布,用于绘制原始文字
$tempImg = imagecreatetruecolor($w, $h);
// 填充背景(浅色杂乱背景)
$bgColor = imagecolorallocate($tempImg, rand(240, 255), rand(240, 255), rand(240, 255));
imagefill($tempImg, 0, 0, $bgColor);
// --- 第一层干扰:背景噪点(会被一起扭曲) ---
for ($i = 0; $i < 300; $i++) {
$color = imagecolorallocate($tempImg, rand(150, 220), rand(150, 220), rand(150, 220));
imagesetpixel($tempImg, rand(0, $w), rand(0, $h), $color);
}
// --- 生成算术逻辑 ---
$num1 = rand(1, .........完整代码请登录后点击上方下载按钮下载查看















网友评论0