《PHP編程:利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法》要點(diǎn):
本文介紹了PHP編程:利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
使用php可以模擬 post 和 get 傳送數(shù)據(jù)到別的網(wǎng)頁或站點(diǎn)PHP編程
$arr=array( 'user'=>'test', 'password'=>'' ); sock_get($post_url,$arr); sock_post($post_url,$arr); //fsocket模擬get提交 function sock_get($url,$query=array()){ $query_str = http_build_query($query); $<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">info</span></a></span> = parse_url($url); $port = isset($info['port'])? $info['port'] : ; $query_str = empty($info["query"])?$query_str:$info["query"].'&'.$query_str; $fp = fsockopen($info["host"], $port, $errno, $errstr, ); if(!$fp){ return FALSE; } //$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">head</span></a></span> = "GET ".$info['path']."?".$info["query"]." HTTP/.\r\n"; $head = "GET ".$info['path']."?".$query_str." HTTP/.\r\n"; $head .= "Host: ".$info['host']."\r\n"; $head .= "\r\n"; $write = fputs($fp,$head); while(!feof($fp)){ $<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">line</span></a></span> = fread($fp,); echo $line; } fclose($fp); return true; } //fsockopen模擬POST function sock_post($url,$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">data</span></a></span>=array()){ $query = http_build_query($data); $info = parse_url($url); $fp = fsockopen($info["host"], , $errno, $errstr, ); $head = "POST ".$info['path']."?".$info["query"]." HTTP/.\r\n"; $head .= "Host: ".$info['host']."\r\n"; $head .= "Referer: http://".$info['host'].$info['path']."\r\n"; $head .= "Content-type: application/x-www-form-urlencoded\r\n"; $head .= "Content-Length: ".strlen(trim($query))."\r\n"; $head .= "\r\n"; $head .= trim($query); $write = fputs($fp, $head); while (!feof($fp)) { $line = fread($fp,); echo $line; } }
以上內(nèi)容是給大家分享的利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的辦法,希望大家能夠喜歡,更多有關(guān)php fsockopen知識請持續(xù)關(guān)注本站,謝謝.PHP編程
《PHP編程:利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法》是否對您有啟發(fā),歡迎查看更多與《PHP編程:利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/8725.html