利用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 相关文章推荐
改进的IP计数器
Oct 09 PHP
mac下Apache + MySql + PHP搭建网站开发环境
Jun 02 PHP
PHP使用Alexa API获取网站的Alexa排名例子
Jun 12 PHP
Codeigniter出现错误提示Error with CACHE directory的解决方案
Jun 12 PHP
CodeIgniter中使用Smarty3基本配置
Jun 29 PHP
PHP根据图片色界在不同位置加水印的方法
Jul 01 PHP
PHP使用数组依次替换字符串中匹配项
Jan 08 PHP
[原创]php实现子字符串位置相互对调互换的方法
Jun 02 PHP
注释PHP和html混合代码的小技巧(分享)
Nov 03 PHP
PHP实现的Redis多库选择功能单例类
Jul 27 PHP
Linux下 php7安装redis的方法
Nov 01 PHP
eval(cmd)与eval($cmd)的区别与联系
Jul 07 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
javascript 计算两个整数的百分比值
2009/12/26 Javascript
基于Jquery的表格隔行换色,移动换色,点击换色插件
2010/12/22 Javascript
js下拉框二级关联菜单效果代码具体实现
2013/08/03 Javascript
js 遍历json返回的map内容示例代码
2013/10/29 Javascript
jQuery中使用Ajax获取JSON格式数据示例代码
2013/11/26 Javascript
JS获取单击按钮单元格所在行的信息
2014/06/17 Javascript
JavaScript学习笔记之JS对象
2015/01/22 Javascript
基于javascript实现彩票随机数生成(简单版)
2020/04/17 Javascript
ionic由于使用了header和subheader导致被遮挡的问题的两种解决方法
2016/09/22 Javascript
常用的几个JQuery代码片段
2017/03/13 Javascript
vue.js组件之间传递数据的方法
2017/07/10 Javascript
浅谈在koa2中实现页面渲染的全局数据
2017/10/09 Javascript
浅谈Vue网络请求之interceptors实际应用
2018/02/28 Javascript
Vue-Cli 3.0 中配置高德地图的两种方式
2019/06/19 Javascript
中高级前端必须了解的JS中的内存管理(推荐)
2019/07/04 Javascript
jQuery实现的记住帐号密码功能完整示例
2019/08/03 jQuery
Node 模块原理与用法详解
2020/05/13 Javascript
el-form 多层级表单的实现示例
2020/09/10 Javascript
让你30分钟快速掌握vue3教程
2020/10/26 Javascript
深入探究Python中变量的拷贝和作用域问题
2015/05/05 Python
windows下Python实现将pdf文件转化为png格式图片的方法
2017/07/21 Python
python装饰器深入学习
2018/04/06 Python
python快排算法详解
2019/03/04 Python
Django后台管理系统的图文使用教学
2020/01/20 Python
django 实现简单的插入视频
2020/04/07 Python
详解tf.device()指定tensorflow运行的GPU或CPU设备实现
2021/02/20 Python
SmartBuyGlasses美国官网:太阳眼镜和眼镜
2017/08/20 全球购物
Spotahome意大利:公寓和房间出租
2020/02/21 全球购物
生物专业个人自荐信范文
2013/11/29 职场文书
大学生创业感言
2014/01/25 职场文书
《只有一个地球》教学反思
2014/02/14 职场文书
抢劫罪辩护词
2015/05/21 职场文书
公文写作:工伤事故分析报告怎么写?
2019/11/05 职场文书
Pandas 稀疏数据结构的实现
2021/07/25 Python
python Tkinter模块使用方法详解
2022/04/07 Python
深入理解pytorch库的dockerfile
2022/06/10 Python