使用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);
$info = 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;
}
//$head = "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)){
$line = fread($fp,);
echo $line;
}
fclose($fp);
return true;
}
//fsockopen模拟POST
function sock_post($url,$data=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 fsockopen 模拟POST/GET传送数据的方法相关文章请关注PHP中文网!
拍客竞拍系统是一款免费竞拍网站建设软件,任何个人可以下载使用,但未经商业授权不能进行商业活动,程序源代码开源,任何个人和企业可以进行二次开发,但不能以出售和盈利为目的。安装方法,将www文件夹里面的所有文件上传至虚拟主机,在浏览器执行http://你的域名/install.php或者直接导入数据库文件执行。本次升级优化了一下内容1,程序和模板完美分离。2,优化了安装文件。3,后台增加模板切换功能。










