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

代码如下:
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'] = $timeout;
if($method == "POST") :
$length = strlen($data);
$options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
"Content-Length: {$length}\r\n".
"P3P: CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\"\r\n".
"cookie: {$cookie}\r\n".
"Connection: close\r\n";
$options['http']['content'] = $data;
else:
$options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
"P3P: CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\"\r\n".
"cookie: {$cookie}\r\n".
"Connection: close\r\n";
endif;$context = stream_context_create($options);
return file_get_contents($url,$context);
}
echo http_open("http://localhost/1.PHP","username=haowei","id=5","POST");

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...