Linux

PHP Curl ile Proxy Kullanmak ve Proxy İstekleri Göndermek

sunucu linux kernel
Share

Merhabalar,

PHP script ile curl komutunu kullanarak proxy aracılığıyla istekler göndereceğiz.

Örnek PHP kodumuz aşağıdaki gibidir.


$url = 'https://google.com';
$proxyauth = 'user:pass';
$proxy = '200.111.182.6';
$proxyPort = '443';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//proxy suport
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
//https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/27.0.1453.94 Safari/537.36");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);

$output = curl_exec($ch);

if(curl_exec($ch) === false)
{
echo ‘Curl error: ‘ . curl_error($ch);
}
else
{
echo ‘Operation completed without any errors’;
}

echo $output;

curl_close($ch);