<?php
$url = "http://www.onlinecha.com/";
$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;
?>
$url = "http://www.onlinecha.com/";
$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;
?>
上面的60.175.203.243:8080可替换为某个有效的http proxy地址,这类http proxy网上有很多,搜一下即可。
以上代码勉勉强强可以用来翻墙,示例:http://as1.brite.biz/bm.php,访问http://as1.brite.biz/bm.php可以显示被封的网站http://briteming.appspot.com的内容,但http://as1.brite.biz/bm.php网页里面的链接 是无效的。
另外一种 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;
}
{
$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;
}
No comments:
Post a Comment