php破解图片验证码
PHP #破解验证码 #类2012-05-26 11:53
解决验证码的问题。
001 | /** |
002 | * Author: zj mail:ggbox@163.com |
003 | * 2010/5/11 |
004 | */ |
005 | class crackimg{ |
006 | private $image =null; |
007 | private $size =0; |
008 | private $im =null; |
009 | private $width =0; |
010 | private $height =0; |
011 | private $char = array (); |
012 | private $string = array (); |
013 | public $code = '' ; |
014 | //某具体验证码对应数字的2值码。 |
015 | private $charCode = array ( |
016 | '0' => '1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,01,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0' , |
017 | '1' => '1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,0,0,0,0,0' , |
018 | '2' => '1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,01,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,01,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,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,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,01,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0' |
026 | ); |
027 |
028 | public function __construct( $url ){ |
029 | $this ->image= $url ; |
030 | $this ->size= getimagesize ( $this ->image); |
031 | $this ->im=imagecreatefrompng( $this ->image); |
032 | $this ->width= $this ->size[0]; |
033 | $this ->height= $this ->size[1]; |
034 | $this ->imgToBinarray(); |
035 | $this ->imgToBinstring(); |
036 | $this ->getCode(); |
037 | } |
038 | //图片对应数值的二值化数组。 |
039 | private function imgToBinarray(){ |
040 | for ( $x =1; $x < $this ->width; $x ++){ |
041 | $flag [ $x ]=false; |
042 | for ( $y =1; $y < $this ->height; $y ++){ |
043 | $color =imagecolorat( $this ->im, $x , $y ); |
044 | if ( $color > 0 && $flag [ $x ] == false){ |
045 | $flag [ $x ] = true; |
046 | } |
047 | if ( $flag [ $x ]==true){ |
048 | $col [ $x ][] = $color ; |
049 | } |
050 | } |
051 | } |
052 |
053 | $n =0; |
054 | foreach ( $col as $k => $v ){ |
055 | $tmparray [] = join( "," , $v ); |
056 | //垂直不重叠的情况下,分隔的字符必定存在空白 |
057 | //如果存在干扰线,应该用定宽分隔比较好。 |
058 | if ( is_array ( $col [ $k -1]) && ! is_array ( $col [ $k +1])){ |
059 | $n ++; |
060 | $this ->char[ $n ]= $tmparray ; |
061 | $tmparray = array (); |
062 | } |
063 | } |
064 | } |
065 | //图片对应数值的二值化字符串。返回数组。 |
066 | private function imgToBinstring(){ |
067 | foreach ( $this ->char as $key => $val ){ |
068 | foreach ( $val as $v ){ |
069 | $this ->string[ $key ].= $v ; |
070 | } |
071 |
072 | } |
073 | } |
074 |
075 | public function getBinarray(){ |
076 | return $this ->char ; |
077 | } |
078 |
079 | public function getBinstring(){ |
080 | return $this ->string; |
081 | } |
082 | //返回图片验证码数值 |
083 | public function getCode(){ |
084 | $precent =0; |
085 | foreach ( $this ->string as $scode ){ |
086 | foreach ( $this ->charCode as $code => $string ){ |
087 | //照某站图片验证,不存在干扰的话,相似比应该是100的。 |
088 | similar_text( $scode , $string , $precent ); |
089 | if ( $precent > 99){ |
090 | $precent =0; |
091 | $this ->code.= $code ; |
092 | } |
093 | } |
094 | } |
095 | } |
096 |
097 | public function display(){ |
098 | //Header("Content-type: image/PNG"); |
099 | echo "<img src='$this->image'></img>" ; |
100 | } |
101 |
102 | } |
103 | $image = "http://www.xxx.com/common/imgcode.php" ;//目标站就隐藏了:) |
104 | //$image="test.png"; |
105 | $png = new crackimg( $image ); |
106 | //$png->display(); |
107 | //print_r($png->getBinstring()); |
108 | print_r( $png ->code); |
相关文章
- PHP公历转农历(阳历转阴历)的类 2012/05/26
- PHP伪静态函数 2012/05/25
- PHP根据时间戳返回星期几的函数 2012/05/24
- PHP魔术常量 2012/05/24
- PHP手册中文翻译补完计划参与方式 2012/05/24
- PHP统计utf8中文字符个数 2012/05/24
- 出现Unable to find the socket transport 'ssl' 解决方法 2012/05/23
- jquery循环map/数组/对象的方法 2012/05/20
- Call to undefined function curl_init()错误的解决方法 2012/05/20
- PHP删除目录/文件夹的三种方法 2012/05/18