我正在尝试检索网址的状态。我正在编写PHP代码来检索它,但我没有得到输出。什么都没有显示出来。
我正在从xml文件中读取url并将其存储在变量中。我在做
file_get_contents($url);
echo $http_respone_header[0];
$url
包含我从xml文件中读取的url。
答案 0 :(得分:1)
您正在做的事情不是获取URL状态,而是获取网站的内容。如果URL错误/无效,则file_get_contents()将返回false,如文档in here中所述
如果您尝试获取状态您只需使用本网站上其他主题中描述的解决方案。
<?php
$url = 'http://www.wp.pl';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
echo $httpCode;
curl_close($handle);
?>
链接到上述主题:here