导航:首页 > 编程语言 > php图片验证码识别

php图片验证码识别

发布时间:2022-11-17 06:10:18

php图片验证码实现

可以用php的GD库做

//随机生成验证码
class randomString
{

function createRandomStr($strLen)
{
list($usec, $sec) = explode(' ', microtime());
(float) $sec + ((float) $usec * 100000);

$number = '';
$number_len = $strLen;
$stuff = '';//附加码显示范围ABCDEFGHIJKLMNOPQRSTUVWXYZ
$stuff_len = strlen($stuff) - 1;
for ($i = 0; $i < $number_len; $i++) {
$number .= substr($stuff, mt_rand(0, $stuff_len), 1);
}
return $number;
}
}
通过ZD库将验证码变成图片
$number = $createStr->createRandomStr('4');//验证码的位数
$number_len = strlen($number);
$_SESSION["VERIFY_CODE"] = $number;

// 生成验证码图片
$img_width = 60;
$img_height = 20;

$img = imageCreate($img_width, $img_height);
ImageColorAllocate($img, 0x6C, 0x74, 0x70);
$white = ImageColorAllocate($img, 0xff, 0xff, 0xff);

$ix = 6;
$iy = 2;
for ($i = 0; $i < $number_len; $i++) {
imageString($img, 5, $ix, $iy, $number[$i], $white);
$ix += 14;
}
for($i=0;$i<200;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img, rand()%100 , rand()%50 , $randcolor);
}

// 输出图片
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));

imagepng($img);
imagedestroy($img);

⑵ 求助!!在php中想实现图片验证码的效果

1.rand一个数串。
2.存入cookie中或session中。
3.将数用gd库方法生成图片。
4.用户输入后与cookie或session对比。
done

⑶ php怎么做图片识别

个人建议:楼主使用php进行图片识别,不如使用ocr文字识别技术来进行图片识别,这样更方便,请看下面的方法:

  1. 首先,在电脑上安装ocr文字识别软件(迅捷ocr文字识别软件)。

  2. 接着,运行ocr,选择上面的‘极速识别’功能。

  3. 然后,点击左上角的‘添加文件’,不需要识别的图片添加进去。

  4. 最后,点击操作下面的‘开始识别’按钮。

希望上方的方法可以帮助到你。

⑷ 如何用PHP生成验证码

PHP生成验证码的原理:使用PHP的GD库,生成一张带验证码的图片,并将验证码保存在Session中。PHP生成验证码的大致流程有:

1、产生一张png的图片;

2、为图片设置背景色;

3、设置字体颜色和样式;

4、产生4位数的随机的验证码;

5、把产生的每个字符调整旋转角度和位置画到png图片上;

6、加入噪点和干扰线防止注册机器分析原图片来恶意破解验证码;

7、输出图片;

8、释放图片所占内存。

session_start();
getCode(4,60,20);

functiongetCode($num,$w,$h){
$code="";
for($i=0;$i<$num;$i++){
$code.=rand(0,9);
}
//4位验证码也可以用rand(1000,9999)直接生成
//将生成的验证码写入session,备验证时用
$_SESSION["helloweba_num"]=$code;
//创建图片,定义颜色值
header("Content-type:image/PNG");
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,0,0,0);
$gray=imagecolorallocate($im,200,200,200);
$bgcolor=imagecolorallocate($im,255,255,255);
//填充背景
imagefill($im,0,0,$gray);

//画边框
imagerectangle($im,0,0,$w-1,$h-1,$black);

//随机绘制两条虚线,起干扰作用
$style=array($black,$black,$black,$black,$black,
$gray,$gray,$gray,$gray,$gray
);
imagesetstyle($im,$style);
$y1=rand(0,$h);
$y2=rand(0,$h);
$y3=rand(0,$h);
$y4=rand(0,$h);
imageline($im,0,$y1,$w,$y3,IMG_COLOR_STYLED);
imageline($im,0,$y2,$w,$y4,IMG_COLOR_STYLED);

//在画布上随机生成大量黑点,起干扰作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx=rand(3,8);
for($i=0;$i<$num;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos,substr($code,$i,1),$black);
$strx+=rand(8,12);
}
imagepng($im);//输出图片
imagedestroy($im);//释放图片所占内存
}

⑸ PHP 绘制网站登录首页图片验证码

几乎所有的网站登录页都会有验证码,验证码是一种安全保护机制,在注册时要求必须有人工操作进行验证,用于防止垃圾注册机大量注册用户账号占用服务器内存从而使服务器瘫痪。
图片验证码的实现十分简单。首先从指定字符集合中随机抽取固定数目的字符,以一种不规则的方法画在画布上,再适当添加一些干扰点和干扰元素,最后将图片输出,一张崭新的验证码就完成了。
先给大家展示下生成的验证码:

点击刷新:

如果大家对实现效果非常满意,请继续往下看。
前端代码如下:
<!DOCTYPE
html>
<html>
<head>
<meta
http-equiv="content-type"
content="text/html;charset=utf-8">
<title>This
is
a
test!</title>
<link
rel="stylesheet"
type="text/css"
href="css/bootstrap.min.css">
</head>
<body>
<form
name="form">
<input
type="text"
placeholder="账号"/><br/>
<input
type="password"
placeholder="密码"/><br/>
<input
type="text"
placeholder="验证码"/>
<img
id="verImg"
src="libs/verification.php"/>
<a
href="#"
class="change"
onclick="changeVer()">点击刷新</a><br/>
<input
type="submit"
value="登录"/>
</form>
<script
type="text/javascript">
//刷新验证码
function
changeVer(){
document.getElementById("verImg").src="libs/verification.php?tmp="+Math.random();
}
</script>
</body>
</html>
php脚本文件验证码的代码如下:
<?php
session_start();
//开启session记录验证码数据
vCode(4,
15);//设置验证码的字符个数和图片基础宽度
//vCode
字符数目,字体大小,图片宽度、高度
function
vCode($num
=
4,
$size
=
20,
$width
=
0,
$height
=
0)
{
!$width
&&
$width
=
$num
*
$size
*
4
/
5
+
15;
!$height
&&
$height
=
$size
+
10;
//设置验证码字符集合
$str
=
"";
//保存获取的验证码
$code
=
''
//随机选取字符
for
($i
=
0;
$i
<
$num;
$i++)
{
$code
.=
$str[mt_rand(0,
strlen($str)-1)];
}
//创建验证码画布
$im
=
imagecreatetruecolor($width,
$height);
//背景色
$back_color
=
imagecolorallocate($im,
mt_rand(0,100),mt_rand(0,100),
mt_rand(0,100));
//文本色
$text_color
=
imagecolorallocate($im,
mt_rand(100,
255),
mt_rand(100,
255),
mt_rand(100,
255));
imagefilledrectangle($im,
0,
0,
$width,
$height,
$back_color);
//
画干扰线
for($i
=
0;$i
<
5;$i++)
{
$font_color
=
imagecolorallocate($im,
mt_rand(0,
255),
mt_rand(0,
255),
mt_rand(0,
255));
imagearc($im,
mt_rand(-
$width,
$width),
mt_rand(-
$height,
$height),
mt_rand(30,
$width
*
2),
mt_rand(20,
$height
*
2),
mt_rand(0,
360),
mt_rand(0,
360),
$font_color);
}
//
画干扰点
for($i
=
0;$i
<
50;$i++)
{
$font_color
=
imagecolorallocate($im,
mt_rand(0,
255),
mt_rand(0,
255),
mt_rand(0,
255));
imagesetpixel($im,
mt_rand(0,
$width),
mt_rand(0,
$height),
$font_color);
}
//随机旋转角度数组
$array=array(5,4,3,2,1,0,-1,-2,-3,-4,-5);
//
输出验证码
//
imagefttext(image,
size,
angle,
x,
y,
color,
fontfile,
text)
@imagefttext($im,
$size
,
array_rand($array),
12,
$size
+
6,
$text_color,
'c:WINDOWSFontssimsun.ttc',
$code);
$_SESSION["VerifyCode"]=$code;
//no-cache在每次请求时都会访问服务器
//max-age在请求1s后再次请求会再次访问服务器,must-revalidate则第一发送请求会访问服务器,之后不会再访问服务器
//
header("Cache-Control:
max-age=1,
s-maxage=1,
no-cache,
must-revalidate");
header("Cache-Control:
no-cache");
header("Content-type:
image/png;charset=gb2312");
//将图片转化为png格式
imagepng($im);
imagedestroy($im);
}
?>
好了,关于小编给大家介绍的php绘制图片验证就给大家介绍这么多,希望对大家有所帮助!

⑹ php怎么实现验证码的

验证码功能机制实现思路

  1. 常规的验证码实现:

    a、产生一张png的图片


    b、为图片设置背景色


    c、设置字体颜色和样式


    d、产生4位数的随机的验证码


    e、把产生的每个字符调整旋转角度和位置画到png图片上


    f、加入噪点和干扰线防止注册机器分析原图片来恶意注册


    g、输出图片


    h、释放图片所占内存


    i、将验证码保存到session或是数据库


    j、将和输入的验证码进行对比

  2. 短信(邮箱)验证码机制:

    a、产生4-6位数的随机的验证码


    b、把产生的每个字符保存到session或是数据库


    c、将验证码发送到用户的手机(邮箱)


    d、用户在规定时间内进行输入


    e、将验证码从session或是数据库中取出


    f、将和输入的验证码进行对比验证

⑺ php验证码怎么实现

1.新建code.php验证码生成文件

在此之前必须打开php的GD库,修改php.ini文件的配置,取消extension=php_gd2.dll前面的分号。代码如下:

<?php

session_start();

//生成验证码图片

Header("Content-type: image/PNG");

$im = imagecreate(44,18);

$back = ImageColorAllocate($im, 245,245,245);

imagefill($im,0,0,$back); //背景

srand((double)microtime()*1000000);

//生成4位数字

for($i=0;$i<4;$i++){

$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));

$authnum=rand(1,9);

$vcodes.=$authnum;

imagestring($im, 5, 2+$i*10, 1, $authnum, $font);

}

for($i=0;$i<100;$i++) //加入干扰象素

{

$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));

imagesetpixel($im, rand()p , rand()0 , $randcolor);

}

ImagePNG($im);

ImageDestroy($im);

$_SESSION['Checknum'] = $vcodes;

?>

2. 显示验证码图片

在需要显示验证码的页面中加入

<input type="text" name="passcode" >

<img src="code.php">

3.判断并获取验证码的值

验证码是通过第一步骤代码中的$_SESSION['Checknum'] = $vcodes;赋的值,所以验证码的值存在$_SESSION['Checknum']当中。在验证页面,使用以下代码,

...

session_start();//启动会话

$code=$_POST["passcode"];

if( $code == $_SESSION["Checknum"])

{...}即可完成验证码登录。

运行截图:

望采纳,谢谢

⑻ php的图片验证码代码

这个是phpcms的验证码,经过十几万个网站经验的,非常好用
<?php

session_start();

$enablegd = 1;
//判断图像处理函数是否存在
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
if(!function_exists($func))
{
$enablegd = 0;
break;
}
}

ob_clean(); //清理缓冲

if($enablegd)
{
//create captcha
$consts = 'cdfgkmnpqrstwxyz23456';
$vowels = 'aek23456789';
for ($x = 0; $x < 6; $x++)
{
$const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //获取$consts中的一个随机数
$vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //获取$vowels中的一个随机数
}
$radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
$_SESSION['checkcode'] = $string = substr($radomstring,0,4); //显示4个字符

$imageX = strlen($radomstring)*8; //图像的宽
$imageY = 20; //图像的高
$im = imagecreatetruecolor($imageX,$imageY); //新建一个真彩色图像

//creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250)); //背景色
$foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255))
);
$foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配颜色并说明透明度
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中间背景
$middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中间背景2

//与左上角的颜色相同的都会被填充
imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
//往图像上写入文字
imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[0]);
imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[2]);
imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/arial.ttf', $string[3]);

//画边框
$border = imagecolorallocate($im, 133, 153, 193);
imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

//画一些随机出现的点
$pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
for ($i=0;$i<80;$i++)
{
imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
}
//画随机出现的线
for ($x=0; $x<9;$x++)
{
if(mt_rand(0,$x)%2==0)
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); //画线
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //画椭圆
}
else
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
header("content-type:image/png\r\n");
imagepng($im);
imagedestroy($im);
}
else
{
$files = glob(XINCHENG_ROOT.'images/checkcode/*.jpg');
if(!is_array($files)) die('请检查文件目录完整性:/images/checkcode/');

$checkcodefile = $files[rand(0, count($files)-1)]; //随机其中一个文件
$_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //获得文件名

header("content-type:image/jpeg\r\n");
include $checkcodefile;
}
?>

⑼ 如何用PHP写图片验证码验证代码

你去php100看看视频教程吧,踏踏实实的看完了,你的问题也就解决了

⑽ 像这样的验证码有没有办法用 PHP 识别

一般没办法 只能用一些办法来搞 比如curl 把图片存下来 然后用txt寸你看到的验证码 然后PHP读取txt内容 或者你用一些打码平台!

阅读全文

与php图片验证码识别相关的资料

热点内容
银河v10驱动重编译 浏览:889
电脑上文件夹右击就会崩溃 浏览:689
右美维持算法 浏览:938
php基础编程教程pdf 浏览:219
穿越之命令与征服将军 浏览:351
android广播重复 浏览:832
像阿里云一样的服务器 浏览:318
水冷空调有压缩机吗 浏览:478
访问日本服务器可以做什么 浏览:433
bytejava详解 浏览:449
androidjava7 浏览:385
服务器在山洞里为什么还有油 浏览:886
天天基金app在哪里下载 浏览:974
服务器软路由怎么做 浏览:292
冰箱压缩机出口 浏览:229
OPT最佳页面置换算法 浏览:645
网盘忘记解压码怎么办 浏览:853
文件加密看不到里面的内容 浏览:654
程序员脑子里都想什么 浏览:434
oppp手机信任app在哪里设置 浏览:189