内容导航:$data[$i][$j]=0,++$i) { for($j=0,$sign[$j] .= $binstr{$base + $i * $column},$rgbarray['green']<125 || $rgbarray['blue'] < 125) { $data[$i][$j]=1
{image}
一 、php 识别验证码
PHP识别验证码(适合大部分验证码)
<?php
$ch= curl_init();
$img='@D:\APMServ5.2.6\www\htdocs\ccb\';//注意@ ,表示文件上传
$data=array(
'type'=>'recognize',
'softID'=>'3',
'softKey'=>'dac04a0f1',
'userName'=>'test',
'passWord'=>'',
'imagePath'=>戚铅者$img,
'codeType'=>'1040',//验证码类高薯型 ,见下面图片
'timeout'=>'60',
'remark'=>'',
'log'=>'0',
'upload'=>'开始识别'
);
// $ch =
curl_init();
//
curl_setopt($ch, CURLOPT_URL, $url);
//
curl_setopt($ch, CURLOPT_POST, 1);
//
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//
curl_exec($ch);
//
curl_close($ch);
//
这段代码提交出去的Content-Type到底是multipart/form-data还是application/x-www-form-
urlencoded呢?我抓包研究了一下,发现Content-Type的类型取决于$data的数激亮据类型。
//
如果$data是字符串,则Content-Type是application/x-www-form-urlencoded。
//
如果$data是k=>v的数组 ,则Content-Type是multipart/form-data
$url='/ZMDemo_PHP/';
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
$result=
curl_exec($ch);
echo$result;
curl_close($ch);
二 、php识别验证码
/这个验证码如何使用PHP自动识别并输出文字 在网上找到2个PHP识别程序 但是不会修改里面的代码其中一个显示 不正确
/ceshi/这个地址是我自己传到空间以后 测试的效果 上面输出的文字跟图片对不上
另外一个程序/phpcrash/直接显示错误下面我提供他们的下载地址/:///希望明白的人给于指导我个人感觉应该是程序需要修改设置
但是我看不是很明白里面的代码上面提供的地址是我自己空间的setImage(' /'); //引号内原值为 $valite->getHec();$ert =
$valite->run();//$ert = "1234";print_r($ert);echo '
'; //引号内 这个部分我自己修改过 原值为 ?>=================以上代码为
内容===========================ImagePath = $Image; } public function getData() {
return $data; } public function getResult() { return $DataArray; } public
function getHec() { $res = imagecreatefromjpeg($this->ImagePath); $size =
getimagesize($this->ImagePath); $data = array(); for($i=0; $i < $size[1];
++$i) { for($j=0; $j < $size[0]; ++$j) { $rgb = imagecolorat($res,$j,$i);
$rgbarray = imagecolorsforindex($res, $rgb); if($rgbarray['red'] < 125 ||
$rgbarray['green']<125 || $rgbarray['blue'] < 125) { $data[$i][$j]=1; }else{
$data[$i][$j]=0; } } } $this->DataArray = $data; $this->ImageSize = $size; }
public function run() { $result=""; // 查找4个数字 $data = array("","","","");
for($i=0;$i<4;++$i) { $x = ($i*(WORD_WIDTH+WORD_SPACING))+OFFSET_X; $y =
OFFSET_Y; for($h = $y; $h < (OFFSET_Y+WORD_HIGHT); ++ $h) { for($w = $x; $w <
($x+WORD_WIDTH); ++$w) { $data[$i].=$this->DataArray[$h][$w]; } } } // 进行关键字匹配
foreach($data as $numKey => $numString) { $max=0.0; $num = 0;
foreach($this->Keys as $key => $value) { $percent=0.0; similar_text($value,
$numString,$percent); if(intval($percent) > $max) { $max = $percent; $num =
$key; if(intval($percent) > 95) break; } } $result.=$num; } $this->data =
$result; // 查找最佳匹配数字 return $result; } public function Draw() { for($i=0;
$i<$this->ImageSize[1]; ++$i) { for($j=0; $j<$this->ImageSize[0]; ++$j) { echo
$this->DataArray[$i][$j]; } echo "\n"; } } public function __construct() {
$this->Keys = array( '0'=>'', '1'=>'', '2'=>'', '3'=>'', '4'=>'', '5'=> '',
'6'=>'', '7'=>'', '8'=>'', '9'=>'', ); } protected $ImagePath; protected
$DataArray; protected $ImageSize; protected $data; protected $Keys; protected
$NumStringArray;}?>==============以上内容为
另外一个程序差不多需要的话自己下载看看比较清楚一些吧为什么没人来看啊这个代码获取的不准确啊 。有没有样式希求,没有的话我自己写了一个验证码。发给你PHP:
error_reporting(E_ALL);
class PNG_READER {
var $pngdata;
var $offset;
var $width;
var $height;
var $bitdepth; //bit depth
var $rowbytes;
var $irowbytes;
var $colortype;
var $bmpdata;
var $code = '';
function PNG_READER(&$data)
{
$this->pngdata = $data;
$this->offset = 0;
}
function _read_raw($len)
{
$start = $this->offset;
$this->offset += $len;
return substr($this->pngdata, $start, $len);
}
//return tag name and data
function _read_chunk(&$tag)
{
$chunk = unpack('Nlength', $this->_read_raw(4));
$data = $this->_read_raw($chunk['length'] + 4);
$chunk = unpack('Ncrc', $this->_read_raw(4));
if ($chunk['crc'] !== crc32($data)) {
exit("crc error\n");
}
$tag = substr($data, 0, 4);
return substr($data, 4);
}
function read()
{
$signature = $this->_read_raw(8);
$sign_str = pack('C8', 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A);
if ($signature != $sign_str) {
exit("invalid signature\n");
}
$tag = '';
do {
$data = $this->_read_chunk($tag);
switch($tag) {
case 'IHDR':
$fileheader =
unpack('Nwidth/Nheight/Cdepth/Ctype/Ccompression/Cfilter/Cinterlace', $data);
$this->bitdepth = $fileheader['depth']; //2 == 2 palette index ,refrer to PLTE
chunk
//the sample depth is always 8 bits.
$this->colortype = $fileheader['type']; //3 == indexed-color
$this->width = $fileheader['width'];
$this->height = $fileheader['height'];
$this->rowbytes = (($fileheader['depth'] * $fileheader['width']) + 7)>> 3;
//$this->row_bytes = ($fileheader['depth'] * $fileheader['width'])>> 3;
break;
case 'IDAT':
$this->irowbytes = $this->rowbytes + 1;
$size = ($this->irowbytes) * $this->height;
$this->bmpdata = gzuncompress($data);
break;
case 'PLET':
break;
default:
break;
}
} while('IEND' !== $tag);
unset($data);
}
function _convert_hex_binstr($hex)
{
$bin['0'] = ' ';
$bin['1'] = ' 1';
$bin['2'] = ' 1 ';
$bin['3'] = ' 11';
$bin['4'] = ' 1 ';
$bin['5'] = ' 1 1';
$bin['6'] = ' 11 ';
$bin['7'] = ' 111';
$bin['8'] = '1 ';
$bin['9'] = '1 1';
$bin['a'] = '1 1 ';
$bin['b'] = '1 11';
$bin['c'] = '11 ';
$bin['d'] = '11 1';
$bin['e'] = '111 ';
$bin['f'] = '1111';
return $bin[$hex];
}
function analyze_row()
{
$binstr = '';
$hexstr = bin2hex($this->bmpdata);
unset($this->bmpdata);
$hexlen = $this->irowbytes * 2;
for ($i = 0; $i <$this->height; $i ++) {
//echo bin2hex(substr($this->bmpdata, $i * $this->irowbytes,
$this->irowbytes));
for ($j = 0; $j <$hexlen; $j ++) {
$pos = $hexlen * $i + $j;
$tmpstr = $this->_convert_hex_binstr($hexstr{$pos});
$binstr .= $tmpstr;
//echo $tmpstr;
}
//echo "\n";
}
$this->_reconstruct($binstr, $hexlen*4, $this->height-1);
}
function _reconstruct($binstr, $column, $row)
{
$base = 29;
for ($j = 0; $j <4; $j ++) {
$sign[$j] = '';
for ($i = 9; $i <$row; $i ++) {
$sign[$j] .= $binstr{$base + $i * $column};
}
$base += 14;
$rcode = $this->_convert_signature_to_num($sign[$j]);
if (0 == $rcode) {
$dot = 11 * $column + 29 + 14 * $j;
if ($binstr{$dot+8} == 0) {
$rcode = 6;
}
}
$this->code .= $rcode;
}
}
function _convert_signature_to_num($str)
{
$fingermark[' '] = 0;
$fingermark[' 1 1'] = 1;
$fingermark[' 11 11'] = 2;
$fingermark[' 1 1 '] = 3;
$fingermark[' 11 '] = 4;
$fingermark['1111 1 '] = 5;
$fingermark['1 '] = 7;
$fingermark[' 11 111 '] = 8;
$fingermark[' 111 1 '] = 9;
return $fingermark[$str];
}
}
$filedata = file_get_contents(' /pagemydns/');
$png = & new PNG_READER($filedata);
$png->read();
$png->analyze_row();
print_r($png->code);
echo "\n";
你直接发代码来看.
三、PHP如何将一个验证码图片内容读取出来都是数字
例如如何将下面的图片获取实际的显示数字/zhmap/?id=2&flag;=1如果php能读取到图片上的文字字符,那网站上登陆注册等弄验证码 ,就是多此一举
验证码的初衷就是为了防止一些软件恶意注册或者灌水
而你的这个要求,显然与这个目的相互违背!你把验证码最终结果写到session里,然后post过来的数跟 session 里面的对比 ,相同为真,不能就是错误
比如 验证码为 1+4 那么把 5写到session 里,然后跟 post 过来的对比 ,就成了用图像识别技术。
四、如何用php做验证码的识别 求大师赐教不胜感激 。。。 。。
验证码识别 没什么好的方法目前 谷歌那个 也不太准确。 。指的是图片那种的验证码恐怕很难!识别验证码最靠谱的就是接入第三方api人工识别你好!
谷歌有个开源的验证码识别引擎
仅代表个人观点,不喜勿喷,谢谢 。