脚本宝典收集整理的这篇文章主要介绍了功能强大的PHP POST提交数据类,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例为大家分享了PHP功能强大的 POST提交数据类,供大家参考,具体内容如下
<div class="js-codecode">
<PRe class="brush:PHP;">
<?php
class Request{
public static function post($url,$post_data = '',$timeout = 5){//curl
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,$url);
curl_setopt ($ch,CURLOPT_POST,1);
if($post_data != ''){
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
}
curl_setopt ($ch,CURLOPT_RETURNtransfer,1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_HEADER,false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
public static function post2($url,$data){//file_get_content
$postdata = http_build_query(
$data
);
$opts = array('http' =>
array(
'method' => 'POST','header' => 'Content-tyPE: application/x-www-form-urlencoded','content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url,false,$context);
return $result;
}
public static function post3($host,$path,$query,$others=''){//fsocket
$post="POST $path HTTP/1.1\r\nHost: $host\r\n";
$post.="Content-type: application/x-www-form-";
$post.="urlencoded\r\n${others}";
$post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
$post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrITe($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return $r;
}
}
?>
以上是脚本宝典为你收集整理的功能强大的PHP POST提交数据类全部内容,希望文章能够帮你解决功能强大的PHP POST提交数据类所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。