function mycurl($date){ if(!$date['url']){die('未给定URL参数.');} $ch = curl_init($date['url']); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; KB974487)'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT); curl_setopt($ch, CURLOPT_AUTOREFERER,true); if( $date['referer']){curl_setopt($ch, CURLOPT_REFERER, $date['referer']);} curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0); curl_setopt($ch, CURLOPT_ENCODING, ' gzip, deflate'); if($date['header']){curl_setopt($ch, CURLOPT_HTTPHEADER, $date['header']);} if($date['cookie_file']){curl_setopt($ch, CURLOPT_COOKIEFILE, $date['cookie_file'] );curl_setopt($ch, CURLOPT_COOKIEJAR, $date['cookie_file'] );} if($date['cookie_str']){curl_setopt($ch, CURLOPT_COOKIE, $date['cookie_str'] );} if($date['post_date']){ curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($date['post_date']));} if($date['post_date_arr']){curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $date['post_date_arr'] );} curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); $cons = curl_exec($ch); curl_close($ch); return $cons; } function getIP(){ $html = mycurl(array( 'url'=>'http://www.baidu.com/baidu?wd=ip', )); if(preg_match('/(.*?)
/s',$html,$mh)){ return $mh[1]; }else{ return '本机IP获取失败'; } }
curl获取IP地址,
标签:
二维码生成中...
扫码阅读