{"id":705,"date":"2014-07-23T13:26:47","date_gmt":"2014-07-23T13:26:47","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=705"},"modified":"2014-07-23T13:26:47","modified_gmt":"2014-07-23T13:26:47","slug":"%e7%94%a8php%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e9%aa%8c%e8%af%81%e7%a0%81%e8%af%86%e5%88%ab","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/705.html","title":{"rendered":"\u7528PHP\u5b9e\u73b0\u7b80\u5355\u9a8c\u8bc1\u7801\u8bc6\u522b"},"content":{"rendered":"<p>\u5728\u6d4f\u89c8blog\u7684\u65f6\u5019\u6dd8\u5230\u7684\u4e00\u4e2a\u4e0d\u9519\u7684\u5e94\u7528&#8211;\u7b80\u5355\u9a8c\u8bc1\u7801\u8bc6\u522b\u3002<\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.rrgod.com\/technique\/871.html\" target=\"_blank\">http:\/\/www.rrgod.com\/technique\/871.html<\/a><\/p>\n<p>\u5199\u4e86\u4e2a\u7b80\u5355\u9a8c\u8bc1\u7801\u7684\u8bc6\u522b\u7a0b\u5e8f\uff0c\u5206\u4eab\u4e0b\u3002\u57fa\u672c\u6b65\u9aa4\u5c31\u662f\u4e8c\u503c\u5316\u3001\u53bb\u566a\u70b9\u3001\u53d6\u5b57\u7b26\u3001\u505a\u5b57\u6a21\u5e93\uff0c\u6700\u540e\u5229\u7528\u5b57\u6a21\u5e93\u5b9e\u73b0\u9a8c\u8bc1\u7801\u8bc6\u522b<\/p>\n<p>\u90e8\u5206\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\nheader('Content-type:text\/html;charset=uft-8');\n\ndefine('WORD_SPACING',9);\/\/\u5b57\u7b26\u95f4\u8ddd\ndefine('LEFT',10);\ndefine('TOP',9);\ndefine('HEIGHT',15);\ndefine('WIDTH',10);\ndefine('COLOR', 215);\/\/\u4e8c\u503c\u5316\u9600\u503c\n\n$filePath = $_GET['p'].'.png';\nlist($width,$height) = getimagesize($filePath);\n$rs = imagecreatefrompng($filePath);\n$sourceData =array();\n\n\/\/\u53d6\u7279\u5f81\u503c\nfor ($i=0; $i &lt; $height; $i++) {\n\tfor ($j=0; $j &lt; $width; $j++) {\n\t\t$index = imagecolorat($rs, $j, $i);\n\t\t$rgb = imagecolorsforindex($rs, $index);\n\t\t\/\/print_r($rgb);\n\t\tif ($rgb['red']&gt;COLOR &amp;&amp; $rgb['blue']&gt;COLOR &amp;&amp; $rgb['green']&gt;COLOR) {\n\t\t\t\/\/echo '1';\n\t\t\t$sourceData[$i][$j]=0;\n\t\t}else{\n\t\t\t\/\/echo '0';\n\t\t\t$sourceData[$i][$j]=1;\n\t\t}\n\t}\n}\n\n\/\/\u53bb\u566a\u70b9 \u9600\u503c5\nfunction clear($sourceData){\n\t$desData = array();\n\t$h =count($sourceData,0);\n\t$w =count($sourceData[0]);\n\n\tfor ($i=1; $i &lt; $h-1; $i++) {\n\t\tfor ($j=1; $j &lt; $w-1; $j++) {\n\t\t\t$value = $sourceData[$i-1][$j]+$sourceData[$i+1][$j]+$sourceData[$i][$j-1]+$sourceData[$i][$j+1]\n                +$sourceData[$i-1][$j-1]+$sourceData[$i+1][$j+1]+$sourceData[$i-1][$j+1]+$sourceData[$i+1][$j-1];\n\t\t\tif ($value&gt;=5) {\n\t\t\t\t$desData[$i-1][$j-1] = 1;\n\t\t\t}else{\n\t\t\t\t$desData[$i-1][$j-1] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn $desData;\n}\n\n\/\/\u5b57\u7b26\u5206\u5272\nfunction getCH($data){\n\n\t\/\/\u7b2c\u4e00\u4e2a\u5de6\u4e0a\u89d2\u5750\u6807\n\t$x = LEFT -1;\n\t$y = TOP -1;\n\n\t$ch=0;\n\tfor ($i=$y; $i &lt; $y + HEIGHT; $i++) {\n\t\tfor ($j=$x; $j &lt; $x + WIDTH; $j++) {\n\t\t\t$chData[0][$ch] = $data[$i][$j];\n\t\t\t$ch++;\n\t\t}\n\t}\n\n\t$ch=0;\n\tfor ($i=$y; $i &lt; $y + HEIGHT; $i++) {\n\t\tfor ($j=$x + WIDTH + WORD_SPACING; $j &lt; $x + 2 * WIDTH + WORD_SPACING; $j++) {\n\t\t\t$chData[1][$ch] = $data[$i][$j];\n\t\t\t$ch++;\n\t\t}\n\t}\n\n\t$ch=0;\n\tfor ($i=$y; $i &lt; $y + HEIGHT; $i++) {\n\t\tfor ($j=$x + 2*(WIDTH + WORD_SPACING); $j &lt; $x + 3 * WIDTH + 2 * WORD_SPACING; $j++) {\n\t\t\t$chData[2][$ch] = $data[$i][$j];\n\t\t\t$ch++;\n\t\t}\n\t}\n\n\t$ch=0;\n\tfor ($i=$y; $i &lt; $y + HEIGHT; $i++) {\n\t\tfor ($j=$x + 3*(WIDTH + WORD_SPACING); $j &lt; $x + 4 * WIDTH + 3 * WORD_SPACING; $j++) {\n\t\t\t$chData[3][$ch] = $data[$i][$j];\n\t\t\t$ch++;\n\t\t}\n\t}\n\n\treturn $chData;\n}\n\n\/*\u663e\u793a\nforeach ($desData as $value) {\n\tforeach ($value as $v) {\n\t\tif($v==1){\n\t\t\techo '\u25a0';\n\t\t} else{\n\t\t\techo '\u25a1';\n\t\t}\/\/echo $v;\n\t}\n\techo \"&lt;br \/&gt;\";\n}*\/\n\n\/*\u5b66\u4e60\u529f\u80fd \u5236\u4f5c\u5b57\u6a21\u5e93\nforeach ($chData as $value) {\n\techo \"'\";\n\tforeach ($value as $v) {\n\t\techo $v;\n\t}\n\techo \"',&lt;br \/&gt;\";\n}*\/\n\n\/\/\u8bc6\u522b\u9a8c\u8bc1\u7801\nfunction vertifyCode($chData){\n\n\t\/\/\u5b57\u6a21\n$typehead = require '.\/zimo.php';\n\n\t$ch = array();\n\t$w = count($chData[0]);\n\t\/*\u5355\u4e2a\u5b57\u7b26\u8bc6\u522b\n\tfor ($i=0; $i &lt; 10; $i++) {\n\t\t$mount=0;\n\t\tfor ($j=0; $j &lt; $w; $j++) {\n\t\t\tif ($chData[0][$j]==$typehead[$i][$j]) {\n\t\t\t\t$mount++;\n\t\t\t}\n\t\t}\n\t\tif ($w-$mount&lt;15) {\n\t\t\t$ch[0]=$i;\n\t\t\tbreak;\n\t\t}\n\t}*\/\n\n\tfor ($i=0; $i &lt; 4; $i++) {\n\t\t$result = array();\n\t\tfor ($k=0; $k &lt; 10; $k++) {\n\t\t\t$mount = 0;\n\t\tif (!is_array($typehead[$k])) {\n\t\t\tfor ($j=0; $j &lt; $w; $j++) {\n\t\t\t\t\/*\n\t\t\t\tif (is_array($typehead[$k])) {\n\t\t\t\t\t$subMount = 0;\n\t\t\t\t\tforeach ($typehead[$k] as $v) {\n\t\t\t\t\t\tfor ($m=0; $m &lt; $w; $w++) {\n\t\t\t\t\t\t\tif ($chData[$i][$m] == $v[$m]) {\n\t\t\t\t\t\t\t\t$subMount++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$sub[]=$subMount;\n\t\t\t\t\t}\n\t\t\t\t\t$mount = max($sub);\n\n\t\t\t\t} else {*\/\n\t\t\t\t\tif ($chData[$i][$j]==$typehead[$k][$j]) {\n\t\t\t\t\t\t$mount++;\n\t\t\t\t\t}\n\t\t\t\t\/\/}\n\t\t\t}\n\t\t}else{\n\t\t\tforeach ($typehead[$k] as $v) {\n\t\t\t\t$subMount = 0;\n\t\t\t\t$sub = array();\n\t\t\t\tfor ($m=0; $m &lt; $w; $m++) {\n\t\t\t\t\tif ($chData[$i][$m] == $v[$m]) {\n\t\t\t\t\t\t$subMount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t$sub[]=$subMount;\n\t\t\t}\n\t\t\t$mount = max($sub);\n\t\t}\n\n\n\t\t\tif ($w-$mount&lt;3) {\n\t\t\t\t$ch[$i]=$k;\n\t\t\t\tbreak;\n\t\t\t}else{\n\t\t\t\t$result[$k]=$w-$mount;\n\t\t\t}\n\t\t}\n\t\t\/\/\u672a\u5339\u914d\u6210\u529f\u5219\u53d6\u6700\u4f18\u7ed3\u679c\n\t\tif (!isset($ch[$i])) {\n\t\t\t$ch[$i]=current(array_keys($result,min($result)));\n\t\t}\n\t}\n\n\treturn $ch;\n}\n\n$desData = clear($sourceData);\n$chData = getCH($desData);\n$digtal = vertifyCode($chData);\n\n$resul = '';\nforeach ($digtal as $v) {\n\t$resul .= $v;\n}\n\n\/\/\u8f93\u51fa\u8bc6\u522b\u7ed3\u679c\necho '\u8bc6\u522b\u7ed3\u679c\uff1a',$resul;\n\n\/*test\nforeach ($desData as $value) {\n\tforeach ($value as $v) {\n\t\techo $v;\n\t}\n\techo \"&lt;br \/&gt;\";\n}\n*\/\n\n\/*test\n$im = imagecreate($width-OFFSET_X-RIGHT, $height - OFFSET_Y - BOTTOM);\n$black = imagecolorallocate($im, 0, 0, 0);\n$white = imagecolorallocate($im, 255, 255, 255);\n$h = count($desData,0);\n$w = count($desData[0]);\n\nfor ($i=0; $i &lt; $h; $i++) {\n\tfor ($j=0; $j &lt; $w; $j++) {\n\t\tif ($desData[$i][$j]==1) {\n\t\t\timagesetpixel($im, $j, $i, $white);\n\t\t}\n\t}\n}\nheader(\"Content-type: image\/jpeg\");\nimagejpeg($im);\n*\/\n\n\n?&gt;<\/pre>\n<p>\u5b8c\u6574\u7a0b\u5e8f\u4e0b\u8f7d\uff1a<a href=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/07\/yzm.zip\">yzm<\/a><\/p>\n<p>\u6d4b\u8bd5URL\uff1ahttp:\/\/127.0.0.1\/yzm\/index.php?p=\u6587\u4ef6\u540d<br \/>\n\u6d4b\u8bd5\u4f8b\u5b50\uff1ahttp:\/\/127.0.0.1\/yzm\/index.php?p=1<\/p>\n<p>\u7ed3\u5408\u4e4b\u524d\u5b66\u4e60\u7684EMlog\u535a\u5ba2\u9a8c\u8bc1\u7801\u751f\u6210\u7684PHP\u4ee3\u7801\uff0c\u8c8c\u4f3c\u8981\u88ab\u8fd9\u6b21\u7684\u8bc6\u522b\u7a0b\u5e8f\u7ed9\u5b8c\u7206\u554a\u2026\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6d4f\u89c8blog\u7684\u65f6\u5019\u6dd8\u5230\u7684\u4e00\u4e2a\u4e0d\u9519\u7684\u5e94\u7528&#8211;\u7b80\u5355\u9a8c\u8bc1\u7801\u8bc6\u522b\u3002 \u539f\u6587\u5730\u5740\uff1ahttp:\/\/www.rrg [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,12],"tags":[259,48],"class_list":["post-705","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-tools","tag-captcha","tag-php"],"views":6270,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=705"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/705\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}