<?php /* php使用curl判断404 * Created on 2016-6-24 * Writer www.youkud.com */ function chkurl($url){ $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10);//设置超时时间 curl_exec($handle); //检查是否404(网页找不到) $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if($httpCode == 404) { return false; }else{ return true; } curl_close($handle); } $url="http://www.youkud.com/asdasd.html"; if(chkurl($url)==true){ echo "存在"; }else{ echo "不存在"; } ?>
运行结果为:不存在