{"id":203,"date":"2013-07-15T13:11:33","date_gmt":"2013-07-15T05:11:33","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=203"},"modified":"2015-02-15T20:49:41","modified_gmt":"2015-02-15T12:49:41","slug":"php-mo-ni-post-ti-jiao-shu-ju","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=203","title":{"rendered":"php\u6a21\u62dfpost\u63d0\u4ea4\u6570\u636e"},"content":{"rendered":"<pre class=\"wrap:true lang:default decode:true \">&lt;?php\n\n\/\/\u4ee5\u7a0b\u5e8f\u767b\u9646\u4e00\u4e2a\u8bba\u575b\u767b\u5f55\u4e3a\u4f8b\nfunction bbslogin($user_login, $password, $host, $port = \"80\") {\n\t\/\/\u9700\u8981\u63d0\u4ea4\u7684post\u6570\u636e\n\t$argv = array('cookie' =&gt; array('user_login' =&gt; $user_login, 'password' =&gt; $password, '_wp_http_referer' =&gt; '\/bbpress\/', 're' =&gt; '', 'remember' =&gt; true));\n\tforeach ($argv['cookie'] as $key =&gt; $value) {\n\t\t$params[] = $key . '=' . $value;\n\t}\n\t$params = implode('&amp;', $params);\n\t$header = \"POST \/bbpress\/bb-login.php HTTP\/1.1rn\";\n\t$header .= \"Host:$host:$portrn\";\n\t$header .= \"Content-Type: application\/x-www-form-urlencodedrn\";\n\t$header .= \"Content-Length: \" . strlen($params) . \"rn\";\n\t$header .= \"Connection: Closernrn\";\n\t$header .= $params;\n\t$fp = fsockopen($host, $port);\n\tfputs($fp, $header);\n\twhile (!feof($fp)) {\n\t\t$str = fgets($fp);\n\t\t\/\/\u4ee5\u4e0b\u662f\u81ea\u5df1\u7684\u903b\u8f91\u4ee3\u7801,\u8fd9\u91cc\u4e3b\u8981\u662f\u6a21\u62dfcookie,\u53ef\u7528\u6765\u540c\u6b65\u767b\u9646\n\t\tif (!(strpos($str, \"Set-Cookie:\") === false)) {\n\t\t\t$tmparray = explode(\" \", $str);\n\t\t\t$cookiearray = explode(\"=\", $tmparray[1]);\n\t\t\t$cookiepaths = explode(\"=\", $tmparray[6]);\n\t\t\t$cookiename = urldecode($cookiearray[0]);\n\t\t\t$cookievalue = urldecode(substr($cookiearray[1], 0, strlen($cookiearray[1]) - 1));\n\t\t\t$cookietime = time() + 3600 * 24 * 7;\n\t\t\t$cookiepath = urldecode(substr($cookiepaths[1], 0, strlen($cookiepaths[1]) - 1));\n\t\t\tsetcookie($cookiename, $cookievalue, $cookietime, $cookiepath);\n\t\t}\n\t}\n\tfclose($fp);\n}\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"wrap:true lang:default decode:true \">&lt;?php\n\/\/ PHP POST\u6570\u636e\u7684\u4e09\u79cd\u65b9\u6cd5\n\/\/ php\u6709\u4e09\u79cd\u65b9\u6cd5\u53ef\u4ee5post\u6570\u636e,\u5206\u522b\u4e3aCurl\u3001socket\u3001file_get_contents:\n\n\/**\n * Socket\u7248\u672c\n * \u4f7f\u7528\u65b9\u6cd5\uff1a\n * $post_string = \"app=socket&amp;version=beta\";\n * request_by_socket('facebook.cn','\/restServer.php',$post_string);\n *\/\nfunction request_by_socket($remote_server, $remote_path, $post_string, $port = 80, $timeout = 30)\n{\n\t$socket = fsockopen($remote_server, $port, $errno, $errstr, $timeout);\n\tif (!$socket) die(\"$errstr($errno)\");\n\n\tfwrite($socket, \"POST $remote_path HTTP\/1.0rn\");\n\tfwrite($socket, \"User-Agent: Socket Examplern\");\n\tfwrite($socket, \"HOST: $remote_serverrn\");\n\tfwrite($socket, \"Content-type: application\/x-www-form-urlencodedrn\");\n\tfwrite($socket, \"Content-length: \" . (strlen($post_string) + 8) . 'rn');\n\tfwrite($socket, \"Accept:*\/*rn\");\n\tfwrite($socket, \"rn\");\n\tfwrite($socket, \"mypost=$post_stringrn\");\n\tfwrite($socket, \"rn\");\n\t$header = \"\";\n\twhile ($str = trim(fgets($socket, 4096))) {\n\t\t$header .= $str;\n\t}\n\t$data = \"\";\n\twhile (!feof($socket)) {\n\t\t$data .= fgets($socket, 4096);\n\t}\n\treturn $data;\n}\n\n\/**\n * Curl\u7248\u672c\n * \u4f7f\u7528\u65b9\u6cd5\uff1a\n * $post_string = \"app=request&amp;version=beta\";\n * request_by_curl('http:\/\/facebook.cn\/restServer.php',$post_string);\n *\/\nfunction request_by_curl($remote_server, $post_string)\n{\n\t$ch = curl_init();\n\tcurl_setopt($ch, CURLOPT_URL, $remote_server);\n\tcurl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);\n\tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\tcurl_setopt($ch, CURLOPT_USERAGENT, \"Jimmy's CURL Example beta\");\n\t$data = curl_exec($ch);\n\tcurl_close($ch);\n\treturn $data;\n}\n\n\/**\n * \u5176\u5b83\u7248\u672c\n * \u4f7f\u7528\u65b9\u6cd5\uff1a\n * $post_string = \"app=request&amp;version=beta\";\n * request_by_other('http:\/\/facebook.cn\/restServer.php',$post_string);\n *\/\nfunction request_by_other($remote_server, $post_string)\n{\n\t$context = array(\n\t\t'http' =&gt; array(\n\t\t\t'method' =&gt; 'POST',\n\t\t\t'header' =&gt; 'Content-type: application\/x-www-form-urlencoded' .\n\t\t\t\t\t\t'rn'.'User-Agent : Jimmy's POST Example beta' .\n\t\t\t\t\t\t'rn'.'Content-length:' . strlen($post_string) + 8,\n\t\t\t'content' =&gt; 'mypost=' . $post_string)\n\t\t);\n\t$stream_context = stream_context_create($context);\n\t$data = file_get_contents($remote_server, false, $stream_context);\n\treturn $data;\n}\n\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/\/\u4ee5\u7a0b\u5e8f\u767b\u9646\u4e00\u4e2a\u8bba\u575b\u767b\u5f55\u4e3a\u4f8b function bbslogin($user_login, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":439,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions\/439"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}