我有一个卷曲功能:
function curl($url, $referer, $type=null){
$agent = ($type != null && $type = 'movil') ? 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' : 'Mozilla/5.0(Windows;U;WindowsNT5.0;en-US;rv:1.4)Gecko/20030624Netscape/7.1(ax)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($ch);
curl_close($ch);
return $page;
}
但是这个函数会根据请求显示我的服务器ip,所以很高兴知道通过代理ip和port使用它的任何方式.Thankyou
答案 0 :(得分:1)
如果目的是隐藏源IP(请求发起服务器的IP),那么使用curl是不可能的,因为它是需要操作原始套接字连接的低级操作。
如果您在向某些网址发出请求时希望使用代理, 然后你必须使用“CURLOPT_PROXY”。
function curl($url, $referer, $type=null){
$agent = ($type != null && $type = 'movil') ? 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' : 'Mozilla/5.0(Windows;U;WindowsNT5.0;en-US;rv:1.4)Gecko/20030624Netscape/7.1(ax)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_PROXY, '8.8.8.8'); // replace
8.8.8.8' with proxy server's IP.
curl_setopt($ch, CURLOPT_PROXYPORT, '2211'); // replace '2211' with Proxy server's port.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($ch);
curl_close($ch);
return $page;
}