怎么通过代理来使用file_get_contents? 公司无法访问外网,必须使用代理,这样file_get_contents函数就无效了,怎么才能让php使用代理呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 curlCURLOPT_HTTPPROXYTUNNEL 代理 同意楼上的http://php.net/manual/en/function.file-get-contents.phpfile-get-contents只支持filename,use_include_path,offset,maxlen。使用代理,可以换用curl 使用curl库通过代理服务器访问网页 <?phpfunction curl_string ($url,$user_agent,$proxy){$ch = curl_init();curl_setopt ($ch, CURLOPT_PROXY, $proxy);curl_setopt ($ch, CURLOPT_URL, $url);curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");curl_setopt ($ch, CURLOPT_HEADER, 1);curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt ($ch, CURLOPT_TIMEOUT, 120);$result = curl_exec ($ch);curl_close($ch);return $result;}$url_page = "http://www.366edu.net";$user_agent = "Mozilla/4.0";$proxy = "http://192.11.222.124:8000";$string = curl_string($url_page,$user_agent,$proxy);echo $string;?> file_get_contents 也可以通过proxyhttp://stackoverflow.com/questions/1336262/file-get-contents-behind-a-proxy $aContext = array( 'http' => array( 'proxy' => 'tcp://192.168.0.2:3128', 'request_fulluri' => true, ),);$cxContext = stream_context_create($aContext);$sFile = file_get_contents("http://www.google.com", False, $cxContext);echo $sFile; 来画个蛇添个足PHP stream_context_create()作用和用法分析创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。作用:创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。函数原型:resource stream_context_create ([ array $options [, array $params ]] ) $url = "http://www.test.com/";$ctx = stream_context_create(array('http' => array('timeout' => 5,'proxy' => 'tcp://127.0.0.8:8080','request_fulluri' => True,)));$result = file_get_contents($url, False, $ctx);echo $result; php能不能连接远程levelDB啊? 工行在线支付接口 API 哪里下载??? php exce执行mencoder进行转码问题。 关于FCK的函数问题 求助!php高手进 能比较通用地匹配文件路径的正则表达式该怎么写? 关于artdialog 插件的问题 pdo事务回滚的问题 linux 下的 php 无法装入 mysql 扩展?如何设置? 谁能详细介绍php中对mssql支持的命令用法 为什么我的curl没用啊 php模糊查询语句哪里错了???mysql
http://php.net/manual/en/function.file-get-contents.php
file-get-contents只支持
filename,use_include_path,offset,maxlen。
使用代理,可以换用curl
<?php
function curl_string ($url,$user_agent,$proxy){$ch = curl_init();
curl_setopt ($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
curl_close($ch);
return $result;}$url_page = "http://www.366edu.net";
$user_agent = "Mozilla/4.0";
$proxy = "http://192.11.222.124:8000";
$string = curl_string($url_page,$user_agent,$proxy);
echo $string;
?>
'http' => array(
'proxy' => 'tcp://192.168.0.2:3128',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);$sFile = file_get_contents("http://www.google.com", False, $cxContext);echo $sFile;
PHP stream_context_create()作用和用法分析创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。
作用:创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。
函数原型:resource stream_context_create ([ array $options [, array $params ]] ) $url = "http://www.test.com/";
$ctx = stream_context_create(array(
'http' => array('timeout' => 5,
'proxy' => 'tcp://127.0.0.8:8080',
'request_fulluri' => True,)
)
);
$result = file_get_contents($url, False, $ctx);
echo $result;