<?php
//function chkurl($url){
// $handle = curl_init($url);
// curl_setopt($handle,CURLOPT_RETURNTRANSFER,TRUE);
// curl_setopt($handle,CURLOPT_CONNECTTIMEOUT,5); //设置超时时间
// curl_exec($handle);
// //检查是否404
// $httpCode = curl_getinfo($handle,CURLINFO_HTTP_CODE);
// var_dump($httpCode);
// if($httpCode == 404){
// return "不存在";
// }else{
// return "存在";
// }
// curl_close($handle);
//}
//function http_status($url) {
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HEADER, 1);
// curl_setopt($ch, CURLOPT_NOBODY, 1);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_TIMEOUT, 5);
// curl_exec($ch);
// $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
// curl_close($ch);
// return ($status == 404) ? '404' : '正常';
//}
//
//$status = http_status('链接');
//var_dump($status);
//测试
//$url = "https://www.baidu.com";
////$notice = chkurl($url);
////echo $notice;
////var_dump(get_headers($url));
//$status = get_headers($url);
//if (strpos($status[0], '404'))
//{
// echo "404";
// echo "<br/>";
//// echo "654654";
//}else{
// echo $status[0].$url.' 正常访问';
//}
$file = fopen("txt文件目录","r");
while(!feof($file))
{
$url = fgets($file);
$status = get_headers(trim($url));
if (strpos($status[0], '404'))
{
echo $status[0]."404";
echo "<br/>";
}else{
echo $url.'正常访问';
echo "<br/>";
}
}
fclose($file);
?>
标签:status,get,url,echo,header,404,file
From: https://www.cnblogs.com/face-every/p/17030205.html