<br />
<b>Warning</b>:  Undefined array key "HTTP_ACCEPT_LANGUAGE" in <b>/www/wwwroot/01xj.net/wp-content/plugins/wp-ue/main.php</b> on line <b>13</b><br />
{"id":529,"date":"2014-10-07T09:47:51","date_gmt":"2014-10-07T01:47:51","guid":{"rendered":"http:\/\/www.01xj.net\/?p=529"},"modified":"2014-10-07T09:47:51","modified_gmt":"2014-10-07T01:47:51","slug":"php%e8%8e%b7%e5%8f%96html%e7%bd%91%e9%a1%b5%e5%86%85%e5%ae%b9%e7%9a%84%e5%a4%9a%e4%b8%aa%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.01xj.net\/?p=529","title":{"rendered":"php\u83b7\u53d6html\u7f51\u9875\u5185\u5bb9\u7684\u591a\u4e2a\u65b9\u6cd5"},"content":{"rendered":"<p><span>\u4f8b1\uff0c\u7528file_get_contents \u4ee5get\u65b9\u5f0f\u83b7\u53d6\u5185\u5bb9\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?php\r\n$url='https:\/\/www.01xj.net\/';\r\n$html = file_get_contents($url);\r\n\/\/print_r($http_response_header);\r\nec($html);\r\nprinthr();\r\nprintarr($http_response_header);\r\nprinthr();\r\n?&gt;<\/pre>\n<p><span>\u4f8b2\uff0c\u7528fopen\u6253\u5f00url, \u4ee5get\u65b9\u5f0f\u83b7\u53d6\u5185\u5bb9\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?\r\n$fp = fopen($url, 'r');\r\nprintarr(stream_get_meta_data($fp));\r\nprinthr();\r\nwhile(!feof($fp)) {\r\n$result .= fgets($fp, 1024);\r\n}\r\necho \"url body: $result\";\r\nprinthr();\r\nfclose($fp);\r\n?&gt;<\/pre>\n<p><span>\u4f8b3\uff0c\u7528file_get_contents\u51fd\u6570\uff0c\u4ee5post\u65b9\u5f0f\u83b7\u53d6url\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?php\r\n$data = array ('foo' =&gt; 'bar');\r\n$data = http_build_query($data);\r\n$opts = array (\r\n'http' =&gt; array (\r\n'method' =&gt; 'POST',\r\n'header'=&gt; \"Content-type: application\/x-www-form-urlencoded\" .\r\n\"Content-Length: \" . strlen($data) . \"\",\r\n'content' =&gt; $data\r\n),\r\n);\r\n$context = stream_context_create($opts);\r\n$html = file_get_contents('http:\/\/localhost\/e\/admin\/test.html', false, $context);\r\necho $html;\r\n?&gt;<\/pre>\n<p><span>\u4f8b4\uff0c\u7528fsockopen\u51fd\u6570\u6253\u5f00url\uff0c\u4ee5get\u65b9\u5f0f\u83b7\u53d6\u5b8c\u6574\u7684\u6570\u636e\uff0c\u5305\u62echeader\u548cbody\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?\r\nfunction get_url ($url,$cookie=false) {\r\n$url = parse_url($url);\r\n$query = $url[path].\"?\".$url[query];\r\nec(\"Query:\".$query);\r\n$fp = fsockopen( $url[host], $url[port]?$url[port]:80 , $errno, $errstr, 30);\r\nif (!$fp) {\r\nreturn false;\r\n} else {\r\n$request = \"GET $query HTTP\/1.1\";\r\n$request .= \"Host: $url[host]\";\r\n$request .= \"Connection: Close\";\r\nif($cookie) $request.=\"Cookie: $cookie\\n\";\r\n$request.=\"\";\r\nfwrite($fp,$request);\r\nwhile(!@feof($fp)) {\r\n$result .= @fgets($fp, 1024);\r\n}\r\nfclose($fp);\r\nreturn $result;\r\n}\r\n}\r\n\/\/\u83b7\u53d6url\u7684html\u90e8\u5206\uff0c\u53bb\u6389header\r\nfunction GetUrlHTML($url,$cookie=false) {\r\n$rowdata = get_url($url,$cookie);\r\nif($rowdata)\r\n{\r\n$body= stristr($rowdata,\"\");\r\n$body=substr($body,4,strlen($body));\r\nreturn $body;\r\n}\r\nreturn false;\r\n}\r\n?&gt;<\/pre>\n<p><span>\u4f8b5\uff0c\u7528fsockopen\u51fd\u6570\u6253\u5f00url\uff0c\u4ee5POST\u65b9\u5f0f\u83b7\u53d6\u5b8c\u6574\u7684\u6570\u636e\uff0c\u5305\u62echeader\u548cbody\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?\r\nfunction HTTP_Post($URL,$data,$cookie, $referrer=\"\") {\r\n\/\/ parsing the given URL\r\n$URL_Info=parse_url($URL);\r\n\/\/ Building referrer\r\nif($referrer==\"\") \/\/ if not given use this script as referrer\r\n$referrer=\"111\";\r\n\/\/ making string from $data\r\nforeach($data as $key=&gt;$value)\r\n$values[]=\"$key=\".urlencode($value);\r\n$data_string=implode(\"&amp;\",$values);\r\n\/\/ Find out which port is needed - if not given use standard (=80)\r\nif(!isset($URL_Info[\"port\"]))\r\n$URL_Info[\"port\"]=80;\r\n\/\/ building POST-request:\r\n$request.=\"POST \".$URL_Info[\"path\"].\" HTTP\/1.1\\n\";\r\n$request.=\"Host: \".$URL_Info[\"host\"].\"\\n\";\r\n$request.=\"Referer: $referer\\n\";\r\n$request.=\"Content-type: application\/x-www-form-urlencoded\\n\";\r\n$request.=\"Content-length: \".strlen($data_string).\"\\n\";\r\n$request.=\"Connection: close\\n\";\r\n$request.=\"Cookie: $cookie\\n\";\r\n$request.=\"\\n\";\r\n$request.=$data_string.\"\\n\";\r\n$fp = fsockopen($URL_Info[\"host\"],$URL_Info[\"port\"]);\r\nfputs($fp, $request);\r\nwhile(!feof($fp)) {\r\n$result .= fgets($fp, 1024);\r\n}\r\nfclose($fp);\r\nreturn $result;\r\n}\r\nprinthr();\r\n?&gt;<\/pre>\n<p><span>\u4f8b6\uff0c\u4f7f\u7528curl\u5e93\uff0ccurl\u5e93\u9700\u8981\u5728php.ini\u4e2d\u5f00\u542fcurl\u6269\u5c55\u3002<\/span><\/p>\n<pre class=\"lang-php prettyprint linenums pre-scrollable\">&lt;?\r\n$ch = curl_init();\r\n$timeout = 5;\r\ncurl_setopt ($ch, CURLOPT_URL, 'http:\/\/www.baidu.com\/');\r\ncurl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);\r\ncurl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);\r\n$file_contents = curl_exec($ch);\r\ncurl_close($ch);\r\necho $file_contents;\r\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b1\uff0c\u7528file_get_contents \u4ee5get\u65b9\u5f0f\u83b7\u53d6\u5185\u5bb9\u3002 &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-529","post","type-post","status-publish","format-standard","hentry","category-phpjsshell"],"_links":{"self":[{"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/posts\/529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.01xj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=529"}],"version-history":[{"count":1,"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":530,"href":"https:\/\/www.01xj.net\/index.php?rest_route=\/wp\/v2\/posts\/529\/revisions\/530"}],"wp:attachment":[{"href":"https:\/\/www.01xj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.01xj.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.01xj.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}