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


Posted in PHP onSeptember 22, 2015

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

$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" 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);
  $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" 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";
  $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" 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,);
    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" 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()){
  $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;
  }
}

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

PHP 相关文章推荐
PHP中的超全局变量
Oct 09 PHP
漂亮但不安全的CTB
Oct 09 PHP
有关phpmailer的详细介绍及使用方法
Jan 28 PHP
PHP中::、-&amp;gt;、self、$this几种操作符的区别介绍
Apr 24 PHP
php将mysql数据库整库导出生成sql文件的具体实现
Jan 08 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(十四)
Jun 26 PHP
php实现的树形结构数据存取类实例
Nov 29 PHP
PHP获取Exif缩略图的方法
Jul 13 PHP
php根据数据id自动生成编号的实现方法
Oct 16 PHP
解决laravel 5.1报错:No supported encrypter found的办法
Jun 07 PHP
PHP编程中的Session阻塞问题与解决方法分析
Aug 07 PHP
Yii2语言国际化的配置教程
Aug 19 PHP
PHP判断字符串长度的两种方法很实用
Sep 22 #PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
Sep 22 #PHP
浅析PHP关键词替换的类(避免重复替换,保留与还原原始链接)
Sep 22 #PHP
PHP实现搜索相似图片
Sep 22 #PHP
从刷票了解获得客户端IP的方法
Sep 21 #PHP
fsockopen pfsockopen函数被禁用,SMTP发送邮件不正常的解决方法
Sep 20 #PHP
分享ThinkPHP3.2中关联查询解决思路
Sep 20 #PHP
You might like
随机广告显示(PHP函数)
2006/10/09 PHP
php连接mysql数据库代码
2009/03/10 PHP
Window下PHP三种运行方式图文详解
2013/06/11 PHP
thinkphp实现上一篇与下一篇的方法
2014/12/08 PHP
JS类中定义原型方法的两种实现的区别
2007/03/08 Javascript
javascript 遍历验证所有文本框的值
2009/08/27 Javascript
JavaScript String.replace函数参数实例说明
2013/06/06 Javascript
AngularJS入门教程之学习环境搭建
2014/12/06 Javascript
jQuery实现的超酷苹果风格图标滑出菜单效果代码
2015/09/16 Javascript
JavaScript判断DIV内容是否为空的方法
2016/01/29 Javascript
仿iframe效果Aajx文件上传实例
2016/11/18 Javascript
JavaScript中校验银行卡号的实现代码
2016/12/19 Javascript
canvas滤镜效果实现代码
2017/02/06 Javascript
javascript 判断一个对象为数组的方法
2017/05/03 Javascript
Django使用多数据库的方法
2017/09/06 Javascript
利用js实现前后台传送Json的示例代码
2018/03/29 Javascript
微信小程序实现点击导航条切换页面
2020/11/19 Javascript
使用vue编写h5公众号跳转小程序的实现代码
2020/11/27 Vue.js
[06:23]2014DOTA2西雅图国际邀请赛 小组赛7月12日TOPPLAY
2014/07/12 DOTA
python并发2之使用asyncio处理并发
2017/12/21 Python
使用python对文件中的单词进行提取的方法示例
2018/12/21 Python
Python pycharm 同时加载多个项目的方法
2019/01/17 Python
python中的协程深入理解
2019/06/10 Python
PyCharm-错误-找不到指定文件python.exe的解决方法
2019/07/01 Python
在linux下实现 python 监控usb设备信号
2019/07/03 Python
pyinstaller还原python代码过程图解
2020/01/08 Python
Keras设置以及获取权重的实现
2020/06/19 Python
使用CSS3设计地图上的雷达定位提示效果
2016/04/05 HTML / CSS
Canvas系列之滤镜效果
2019/02/12 HTML / CSS
Lookfantastic德国官网:英国知名美妆购物网站
2017/06/11 全球购物
销售人员个人求职信
2013/09/26 职场文书
公司新员工的演讲稿注意事项
2014/01/01 职场文书
派出所所长先进事迹
2014/05/19 职场文书
风雨哈佛路观后感
2015/06/03 职场文书
不同品牌、不同型号对讲机如何互相通联
2022/02/18 无线电
nginx搭建NFS网络文件系统
2022/04/14 Servers