首页 > 开发 > PHP > 正文

利用PHP fsockopen 模拟POST/GET传送数据的方法

2024-05-04 23:39:06
字体:
来源:转载
供稿:网友

使用php可以模拟post和get传送数据到别的网页或者是站点,那么怎么传送数据呢?下面由小编给大家介绍利用PHP fsockopen 模拟POST/GET传送数据的方法,需要的朋友一起看看吧

使用php可以模拟 post 和 get 传送数据到别的网页或站点

 

 
  1. $arr=array
  2. 'user'=>'test'
  3. 'password'=>'' 
  4. ); 
  5. sock_get($post_url,$arr); 
  6. sock_post($post_url,$arr);  
  7. //fsocket模拟get提交 
  8. function sock_get($url,$query=array()){ 
  9. $query_str = http_build_query($query); 
  10. #FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=info&k=info&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" 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); 
  11. $port = isset($info['port'])? $info['port'] : ; 
  12. $query_str = emptyempty($info["query"])?$query_str:$info["query"].'&'.$query_str
  13. $fp = fsockopen($info["host"], $port$errno$errstr, ); 
  14. if(!$fp){ 
  15. return FALSE; 
  16. //#FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=head&k=head&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" 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"; 
  17. $head = "GET ".$info['path']."?".$query_str." HTTP/./r/n"
  18. $head .= "Host: ".$info['host']."/r/n"
  19. $head .= "/r/n"
  20. $write = fputs($fp,$head); 
  21. while(!feof($fp)){ 
  22. #FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=line&k=line&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" 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,); 
  23. echo $line
  24. fclose($fp); 
  25. return true; 
  26. //fsockopen模拟POST 
  27. function sock_post($url,#FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=data&k=data&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" 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()){ 
  28. $query = http_build_query($data);  
  29. $info = parse_url($url); 
  30. $fp = fsockopen($info["host"], , $errno$errstr, ); 
  31. $head = "POST ".$info['path']."?".$info["query"]." HTTP/./r/n"
  32. $head .= "Host: ".$info['host']."/r/n"
  33. $head .= "Referer: http://".$info['host'].$info['path']."/r/n"
  34. $head .= "Content-type: application/x-www-form-urlencoded/r/n"
  35. $head .= "Content-Length: ".strlen(trim($query))."/r/n"
  36. $head .= "/r/n"
  37. $head .= trim($query); 
  38. $write = fputs($fp$head); 
  39. while (!feof($fp)) 
  40. $line = fread($fp,); 
  41. echo $line

以上内容是给大家分享的利用PHP fsockopen 模拟POST/GET传送数据的方法,希望大家能够喜欢,更多有关php fsockopen知识请持续关注本站,谢谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表