指定ip访问网址
function get($url,$rerror = 0,$ip = ''){
$ch = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
if($ip){
$tmparr = parse_url($url);
$resolve = [$tmparr['host'].':'.($tmparr['scheme']=='https'?'443':'80').':'.$ip];
curl_setopt($ch, CURLOPT_RESOLVE, $resolve);
}
//默认使用iPv4
if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
$sContent = curl_exec($ch);
var_dump($sContent);
$aStatus = curl_getinfo($ch);
var_dump($aStatus);
curl_close($ch);
if(intval($aStatus["http_code"])==200){
return $sContent;
}else{
if($rerror){
return [
'error'=>'返回为空',
'info'=>$aStatus
];
}else{
return false;
}
}
}
try{
$content = get('https://www.ceshi.cn/browse/miaodongpinpai/?cacheHtmlTime='.time(),0,'116.163.46.151');
print_r($content);
}catch(Exception $e){
var_dump($e->getMessage());
}