我正在設置curl以使用代理服務器。該網址是由html表單提供的,這並不是問題。沒有代理,它工作正常。我在這個網站和其他網站上找到了代碼,但它們不起作用。任何幫助找到正確的解決方案將不勝感激。我覺得波紋管很接近,但我錯過了一些東西。謝謝。如何通過代理使用CURL?
波紋管代碼我適應從這裏http://www.webmasterworld.com/forum88/10572.htm但它在線返回有關失蹤T_VARIABLE的錯誤消息12
<?
$url = '$_POST[1]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1)
curl_exec ($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
echo '<br />';
print_r($curl_info);
?>
波紋管是從curl through proxy returns no content
<?
$proxy = "66.96.200.39:80";
$proxy = explode(':', $proxy);
$url = "$_POST[1]";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_HEADER, 1);
$exec = curl_exec($ch);
echo curl_error($ch);
print_r(curl_getinfo($ch));
echo $exec;
?>
目前住在鵜鶘-cement.com,但也不起作用。
更新: 感謝您的幫助,我做了上述變更。現在它只返回一個空白屏幕。
<?
$url = $_POST['1'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_exec ($ch);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>
你缺少第12行 – 2011-03-06 16:56:30
還,您需要更改$網址分號= '$ _ POST [1]' 到$ URL = $ _ POST [1] - 否則,$ URL將是一個字符串,而不是你想要的網址 – yoavmatchulsky 2011-03-06 17:06:21
此外,$ _POST數組中的鍵是一個字符串,不是一個整數,所以你希望它說'$ _POST ['1']' – fiiv 2011-03-06 17:20:24