<?php $url = "http://www.kxblogs.com/n/20161108/74429879.html"; $ch = curl_init (); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 200); curl_setopt($ch, CURLOPT_HEADER, false); //不需要输出头部信息 curl_setopt($ch, CURLOPT_NOBODY, true); //不用输出内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //超时重试 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //抓取转跳 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); //post方式提交 curl_exec($ch); $a = curl_getinfo($ch,CURLINFO_HTTP_CODE); //获取url响应 curl_close($ch); return $a; ?>
这样的判断方式千万别批量使用,不然你懂的。