加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

实现获取http内容的php函数分享

发布时间:2020-12-12 20:03:49 所属栏目:PHP教程 来源:网络整理
导读:代码如下: function http_open($url,$data,$cookie = null,$method = "GET",$timeout = 60) { $options = array(); $options['http']['method'] = $method; $options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $options['http']['timeout'] = $

代码如下:
function http_open($url,$data,$cookie = null,$method = "GET",$timeout = 60) {
$options = array();
$options['http']['method'] = $method;
$options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$options['http']['timeout'] = $timeout;
if($method == "POST") :
$length = strlen($data);
$options['http']['header'] = "Content-type: application/x-www-form-urlencodedrn".
"Content-Length: {$length}rn".
"P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"rn".
"cookie: {$cookie}rn".
"Connection: closern";
$options['http']['content'] = $data;
else:
$options['http']['header'] = "Content-type: application/x-www-form-urlencodedrn".
"P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"rn".
"cookie: {$cookie}rn".
"Connection: closern";
endif;$context = stream_context_create($options);
return file_get_contents($url,$context);
}
echo http_open("http://localhost/1.php","username=haowei","id=5","POST");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读