標籤:else 資訊 方式 host return 請求 res nec useragent
網上很多代理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]"); //Proxy 伺服器地址
curl_setopt($ch, CURLOPT_PROXYPORT,$arrip[1]); //Proxy 伺服器連接埠
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