本文是一个php实现获取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); $option
本文是一个php实现获取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-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, 0, $context);
}
echo http_open("http://localhost/1.php", "username=haowei", "id=5", "POST");
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!