飘易博客(作者:Flymorn)
订阅《飘易博客》RSS,第一时间查看最新文章!
飘易首页 | 留言本 | 关于我 | 订阅Feed

PHP:file_get_contents的代理使用方法

Author:flymorn Source:飘易
Categories:PHP编程 PostTime:2011-1-21 1:23:03
正 文:
   PHP使用file_get_contents的代理方法获取远程网页的代码。

<?php
    $url = "http://www.piaoyi.org/";     
    $ctx = stream_context_create(array(     
       'http' => array('timeout' => 5,  
       'proxy' => 'tcp://60.175.203.243:8080',   
       'request_fulluri' => True,)     
    )     
    );     
    $result = file_get_contents($url, False, $ctx);     
    echo $result;  
?>
   

    另外一种 curl 的方式使用代理的方法:
function postPage($url)
{
$response = "";
$rd=rand(1,4);
$proxy='http://221.214.27.253:808';
if($rd==2) $proxy='http://222.77.14.56:8088';
if($rd==3) $proxy='http://202.98.123.126:8080';
if($rd==4) $proxy='http://60.14.97.38:8080';

if($url != "") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$response = curl_exec($ch);
if(curl_errno($ch)) $response = "";
curl_close($ch);
}
return $response;
}
作者:flymorn
来源:飘易
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。
上一篇:JS读写Cookie设置过期时间
下一篇:vps教程:Linux中常用的命令
6条评论 “PHP:file_get_contents的代理使用方法”
2011-1-22 10:59:00
此文相当有用,申请转载!!
2011-1-22 11:43:23
看看、、、、、、、、、、
2011-1-25 15:05:19
这个有什么用呢?

是不是可以下载人家网站的?
2011-2-11 15:24:47
路过,瞧瞧不错,特意支持一下。
2011-2-14 15:59:25


情人节路过踩踩。。。支持一下
2014-2-23 10:48:52
学习下,挺有用处的,字数字数
发表评论
名称(*必填)
邮件(选填)
网站(选填)

记住我,下次回复时不用重新输入个人信息
© 2007-2010 飘易博客 Www.Piaoyi.Org 原创文章版权由飘易所有 渝ICP备07006361号