php curl 代理ip訪問url
網上很多代理ip來訪問url,具體幹什麽我也不知道,寫代碼:
$header //請求頭
$cookie //存儲cookie
$arrip //ip地址的地址及端口
$params //
public function dorequest($arrip = array(),$url,$header,$timeout = 20000,$method=‘,$cookie‘){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理認證模式
curl_setopt($ch, CURLOPT_PROXY, "$arrip[0]"); //代理服務器地址
curl_setopt($ch, CURLOPT_PROXYPORT,$arrip[1]); //代理服務器端口
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗證證書和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);//設置鏈接
//curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
if(!defined(‘CURLOPT_TIMEOUT_MS‘)){
$res = curl_setopt($ch, CURLOPT_TIMEOUT,30); //設置1秒超時
}
else {
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);//存儲cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); }
if(!defined(‘CURLOPT_CONNECTTIMEOUT_MS‘))
{
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
} else {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $timeout); }
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設置是否返回信息
$method = strtoupper($method);
if($method == ‘POST‘){
curl_setopt($ch, CURLOPT_POST, 1);//設置為POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
}
if($header)
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} //設置跳轉location 最多3次
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
$response = curl_exec($ch);//接收返回信息
}
php curl 代理ip訪問url