文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用fsockopen发送post信息的函数

使用fsockopen发送post信息的函数

时间:2007-02-17  来源:PHP爱好者

使用fsockopen发送post信息的函数
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
作者/来源:zhao214
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
使用fsockopen发送post信息的函数
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
zhao214
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
function httprequest($fp,$url,$http_method,$body="",$referer="")
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
{
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$httpversion = "HTTP/1.0";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$agent = "zhao214/1.0";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$content_type = "application/x-www-form-urlencoded";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if(empty($url))
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$url = "/";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers = $http_method." ".$url." ".$httpversion." ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if(!empty($agent))
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= "User-Agent: ".$agent." ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if(!empty($accept))
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= "Accept: ".$accept." ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if(!empty($referer))
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= "Referer: ".$referer." ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if($http_method == "POST") {
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if(!empty($body)) {
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= "Content-type: $content_type ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= "Content-length: ".strlen($body)." ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$headers .= " ";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
fwrite($fp,$headers.$body);
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
while($currentHeader = fgets($fp,4096)) {
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
if($currentHeader == " ")
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
break;
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$pagecontent = fread($fp,500000);
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
return $pagecontent;
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
/////////example::
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$data = "";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
while(list($k,$v) = each($HTTP_POST_VARS)){
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$data .= urlencode($k)."=".urlencode($v)."&";
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$fp = fsockopen("localhost", 80, &$errno, &$errstr, 100);
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
$out = httprequest($fp,"/someurl.php","POST",$data);
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
print $out;
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
}
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
method=post>
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
name
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob
pass
ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1ob

ww w.china it power.co9jtN4NcW8iKK1Kuf8rwyCx1o
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载