利用PHP fsockopen 模拟POST/GET传送数据的方法
发布时间:2020-12-12 21:05:26 所属栏目:PHP教程 来源:网络整理
导读:使用php可以模拟 post 和 get 传送数据到别的网页或站点 '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); $ = parse_ur
使用php可以模拟 post 和 get 传送数据到别的网页或站点 '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);
$ = 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;
}
//$ = "GET ".$info['path']."?".$info["query"]." HTTP/.rn";
$head = "GET ".$info['path']."?".$query_str." HTTP/.rn";
$head .= "Host: ".$info['host']."rn";
$head .= "rn";
$write = fputs($fp,$head);
while(!feof($fp)){
$ = fread($fp,);
echo $line;
}
fclose($fp);
return true;
}
//fsockopen模拟POST
function sock_post($url,$=array()){
$query = http_build_query($data);
$info = parse_url($url);
$fp = fsockopen($info["host"],);
$head = "POST ".$info['path']."?".$info["query"]." HTTP/.rn";
$head .= "Host: ".$info['host']."rn";
$head .= "Referer: http://".$info['host'].$info['path']."rn";
$head .= "Content-type: application/x-www-form-urlencodedrn";
$head .= "Content-Length: ".strlen(trim($query))."rn";
$head .= "rn";
$head .= trim($query);
$write = fputs($fp,$head);
while (!feof($fp))
{
$line = fread($fp,);
echo $line;
}
}
以上内容是给大家分享的利用PHP fsockopen 模拟POST/GET传送数据的方法,希望大家能够喜欢,更多有关php fsockopen知识请持续关注本站,谢谢。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |