{"id":889,"date":"2013-09-03T14:49:35","date_gmt":"2013-09-03T06:49:35","guid":{"rendered":"http:\/\/hesiwei.cn\/?p=889"},"modified":"2013-09-03T14:49:35","modified_gmt":"2013-09-03T06:49:35","slug":"php%e4%b8%ad%e4%bd%bf%e7%94%a8curl%e6%96%b9%e5%bc%8f%e6%8a%93%e5%8f%96%e7%bd%91%e9%a1%b5%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/hesiwei.cn\/?p=889","title":{"rendered":"PHP\u4e2d\u4f7f\u7528curl\u65b9\u5f0f\u6293\u53d6\u7f51\u9875\u4ee3\u7801"},"content":{"rendered":"<div><span>PHP\u6293\u53d6\u9875\u9762\u7684\u4e3b\u8981\u65b9\u6cd5\uff1a<span>\u00a0<\/span><\/span><span>1. file()\u51fd\u6570<span>\u00a0<\/span><\/span><br \/>\n<span>2. file_get_contents()\u51fd\u6570<span>\u00a0<\/span><\/span><br \/>\n<span>3. fopen()-&gt;fread()-&gt;fclose()\u6a21\u5f0f<span>\u00a0<\/span><\/span><br \/>\n<span>4.curl\u65b9\u5f0f<span>\u00a0<\/span><\/span><br \/>\n<span>5. fsockopen()\u51fd\u6570 socket\u6a21\u5f0f<span>\u00a0<\/span><\/span><br \/>\n<span>6. \u4f7f\u7528\u63d2\u4ef6(\u5982\uff1a<a href=\"http:\/\/sourceforge.net\/projects\/snoopy\/\">http:\/\/sourceforge.net\/projects\/snoopy\/<\/a>)<span>\u00a0<\/span><\/span><\/p>\n<p><!--more--><\/p>\n<\/div>\n<div><span><span>\u4ee5\u4e0b\u662f\u4f7f\u7528curl\u65b9\u5f0f\u4ee3\u7801\uff1a<\/span><\/span><\/div>\n<div><span><span><span>\u4f7f\u7528curl\u5fc5\u987b\u7a7a\u95f4\u5f00\u542fcurl\u3002\u65b9\u6cd5\uff1awindows\u4e0b\u4fee\u6539php.ini\uff0c\u5c06extension=php_curl.dll\u524d\u9762\u7684\u5206\u53f7\u53bb\u6389\uff0c\u800c\u4e14\u9700\u8981\u62f7\u8d1dssleay32.dll\u548clibeay32.dll\u5230C:\\WINDOWS\\system32\u4e0b\uff1bLinux\u4e0b\u8981\u5b89\u88c5curl\u6269\u5c55\u3002<\/span><\/span><\/span><\/div>\n<div>\n<div>\n<div>&lt;?php<br \/>\n$<span style=\"color: #cc33ff;\"><b>f1<\/b><\/span>=<span style=\"color: #ff6600;\">0<\/span><span style=\"color: #009900;\">;<\/span><br \/>\n$<span style=\"color: #cc33ff;\"><b>f2<\/b><\/span>=<span style=\"color: #ff6600;\">1<\/span><span style=\"color: #009900;\">;<\/span><br \/>\n$ch = curl_init()<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_POST, <span style=\"color: #ff6600;\">0<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>\/\/curl_setopt($ch, CURLOPT_POSTFIELDS, <span style=\"color: #ff3366;\">&#8220;f=check_login&#8221;<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_HEADER,<span style=\"color: #ff6600;\">0<\/span>)<span style=\"color: #009900;\">;<\/span><br \/>\ncurl_setopt($ch, CURLOPT_HTTPHEADER,array(&#8216;Accept-Language: zh-cn&#8217;,&#8217;Connection: Keep-Alive&#8217;,&#8217;Cache-<span style=\"color: #0000ff;\"><b>Control<\/b><\/span>: <span style=\"color: #0000ff;\"><b>no<\/b><\/span>-cache&#8217;))<span style=\"color: #009900;\">;<\/span><br \/>\ncurl_setopt($ch, CURLOPT_USERAGENT,<span style=\"color: #ff3366;\">&#8220;Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.1 (KHTML, like Gecko) Chrome\/21.0.1180.79 Safari\/537.1&#8221;<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_RETURNTRANSFER,<span style=\"color: #ff6600;\">1<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_COOKIEFILE, <span style=\"color: #ff3366;\">&#8220;cookie.txt&#8221;<\/span>)<span style=\"color: #009900;\">;<\/span><br \/>\n\/\/curl_setopt($ch, CURLOPT_COOKIEJAR, <span style=\"color: #ff3366;\">&#8220;cookie.txt&#8221;<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_URL,<span style=\"color: #ff3366;\">&#8220;URL\u5730\u5740&#8221;<\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, <span style=\"color: #0000ff;\"><b>false<\/b><\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_setopt($ch, CURLOPT_FOLLOWLOCATION, <span style=\"color: #0000ff;\"><b>true<\/b><\/span>)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>$result = curl_exec ($ch)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>curl_close ($ch)<span style=\"color: #009900;\">;<\/span><\/p>\n<p>print_r($result)<span style=\"color: #009900;\">;<\/span><br \/>\n?&gt;<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u6293\u53d6\u9875\u9762\u7684\u4e3b\u8981\u65b9\u6cd5\uff1a\u00a01. file()\u51fd\u6570\u00a0 2. file_get_contents()\u51fd\u6570\u00a0 3. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-889","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=889"}],"version-history":[{"count":0,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/889\/revisions"}],"wp:attachment":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=889"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}