你如果在 PHP 使用 cURL 模組來連外,可以參考如下用法:
http://stackoverflow.com/questions/5211887/how-to-use-curl-via-a-proxy
確認一下 如果我用下列語法
<pre class="c" name="code">
$url = 'http://tw.yahoo.com';
$proxy = '192.168.3.1:805';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
他應該要連到tw.yahoo.com才對,是這樣嗎?
感謝
上述語法執行後是一片空白,煩請大家指點迷津
感謝
我用底下的程式碼(及 proxy)
Load 出 Yahoo 首頁大概要花七秒鐘
參考看看
<pre class="c" name="code">
<?php
$url = 'http://tw.yahoo.com';
$proxy = '162.216.155.136:7808'; //'192.168.3.1:805';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXY, null);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>