怎么样用php语言实现通过proxy代理服务器访问网站呢??
发布网友
发布时间:2022-04-06 03:17
我来回答
共1个回答
热心网友
时间:2022-04-06 04:47
function curl_string ($url,$timeout = 3,$proxy=1){
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
Tor 地址与端口
$tor = 'http://www.aimilife.com'; //这里是你的代理服务器
连接超时设置
$timeout = 3;
$ack = curl_init();
if($proxy)
{
curl_setopt($ack, CURLOPT_PROXY, $tor);
}
curl_setopt($ack, CURLOPT_URL, $url);
curl_setopt($ack, CURLOPT_HEADER, 0);
curl_setopt($ack, CURLOPT_USERAGENT, $agent);
curl_setopt($ack, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ack, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ack, CURLOPT_TIMEOUT, $timeout);
$result = curl_exec($ack);
curl_close($ack);
return $result;
}