2011-08-12 8 views
0

私のvpsの1つにsquidを使用してプロキシをセットアップした後、このプロキシスクリプトを作成して、wamp、localhost上でうまく動作します。サーバーが動作していないと私は理由を把握することができません。プロキシを使用し、curlを使用し、ローカルホストではなくサーバー上で作業する

$proxy = "xx.xx.xxx.xx:3128"; 
$proxy = explode(':', $proxy); 
$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_USERAGENT, 'Googlebot/1.0 ([email protected] http://googlebot.com/)'); 
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8"); 
curl_setopt($ch, CURLOPT_REFERER, "http://tamilwin.com/"); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
$result = curl_exec ($ch); 

ありがとうございます。

更新

私は自分のサーバー上で取得エラーがプロキシホストが有効でないかもしれcURL error number:7cURL error:couldn't connect to host

+0

これは機能しませんか?どのようなエラーや反応が得られますか? – Mob

+0

エラーが発生すると、cURLエラー番号:7cURLエラー:ホスト –

+0

に接続できませんでした。つまり、詐欺しようとしているため、curlがそのIP –

答えて

0

です。 telnet xx.xx.xxx.xx 3128(ローカルPCから)を試す 正常に接続できますか?

0

私は同様の問題を抱えていますが、localhostではうまく動作しますが、私のサーバではうまく動作しません。私はそれが動作するかどうかを知ることができる検出スクリプトを書いた。

<?php 

//$url = 'https://www.google.com'; 
// to check your proxy 
$url = 'http://whatismyipaddress.com/'; 
$proxy = 'x.x.x.x:3128'; 

// create curl resource 
$ch = curl_init(); 

// set options 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_PROXY, $proxy); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // read more about HTTPS http://stackoverflow.com/questions/31162706/how-to-scrape-a-ssl-or-https-url/31164409#31164409 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_CAINFO, file_exists('\cacert.pem')); 
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy); 


curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 

// $output contains the output string 
$output = curl_exec($ch); 

// close curl resource to free up system resources 
curl_close($ch); 

//echo $output; 

$check = stripos($output,'</html>'); 
// if there was a match in the stripos (string postion) function echo that the 
//proxy got the data and works 
if($check > 0) 
{ 
echo $proxy." Works! 
"; 
// or else echo it doesn't work 
}else{ 
echo $proxy." Is Dead! 
"; 
} 


?> 
関連する問題