利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法
使用php可以模擬 post 和 get 傳送數(shù)據(jù)到別的網(wǎng)頁(yè)或站點(diǎn)
$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知識(shí)請(qǐng)持續(xù)關(guān)注本站,謝謝。
- PHP基于curl模擬post提交json數(shù)據(jù)示例
- php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據(jù)的方法
- PHP socket 模擬POST 請(qǐng)求實(shí)例代碼
- php模擬post上傳圖片實(shí)現(xiàn)代碼
- PHP模擬post提交數(shù)據(jù)方法匯總
- php實(shí)現(xiàn)模擬post請(qǐng)求用法實(shí)例
- php模擬post提交數(shù)據(jù)的方法
- php curl模擬post提交數(shù)據(jù)示例
- php curl模擬post請(qǐng)求小實(shí)例
- php模擬post提交請(qǐng)求調(diào)用接口示例解析
相關(guān)文章
PHP數(shù)組內(nèi)存利用率低和弱類型詳細(xì)解讀
本篇文章主要介紹了PHP數(shù)組內(nèi)存利用率低和弱類型詳細(xì)解讀,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-08-08
Laravel框架Eloquent ORM簡(jiǎn)介、模型建立及查詢數(shù)據(jù)操作詳解
這篇文章主要介紹了Laravel框架Eloquent ORM簡(jiǎn)介、模型建立及查詢數(shù)據(jù)操作,結(jié)合實(shí)例形式詳細(xì)分析了laravel框架Eloquent ORM基本概念、原理、模型建立及數(shù)據(jù)查詢等相關(guān)使用技巧,需要的朋友可以參考下2019-12-12
thinkphp項(xiàng)目如何自定義微信分享描述內(nèi)容
本文主要講述:在thinkphp框架中,如何獲取微信分享接口權(quán)限、如何設(shè)置安全域名、如何修改微信分享標(biāo)題、修改微信分享描述、修改微信分享圖片、如何定制微信分享內(nèi)容2017-02-02
Laravel5.5 數(shù)據(jù)庫(kù)遷移:創(chuàng)建表與修改表示例
今天小編就為大家分享一篇Laravel5.5 數(shù)據(jù)庫(kù)遷移:創(chuàng)建表與修改表示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
ThinkPHP入庫(kù)出現(xiàn)兩次反斜線轉(zhuǎn)義及數(shù)據(jù)庫(kù)類轉(zhuǎn)義的解決方法
這篇文章主要介紹了ThinkPHP入庫(kù)出現(xiàn)兩次反斜線轉(zhuǎn)義及數(shù)據(jù)庫(kù)類轉(zhuǎn)義的解決方法,主要通過(guò)針對(duì)magic_quotes_gpc開(kāi)啟的情況下進(jìn)行檢查與判斷轉(zhuǎn)義來(lái)實(shí)現(xiàn),需要的朋友可以參考下2014-11-11
默默小談PHP&MYSQL分頁(yè)原理及實(shí)現(xiàn)
默默小談PHP&MYSQL分頁(yè)原理及實(shí)現(xiàn)...2007-01-01

