I am trying to retrieve the status of the url. I am writing php code to retrieve it but i am not getting the output. Nothing is being displayed.
I am reading the url's from the xml file a开发者_运维技巧nd storing it in variable. I am doing
file_get_contents($url);
echo $http_respone_header[0];
$url
contains the url which i have read from the xml file.
The thing You are doing is not getting URL status but content of the site. In case of wrong/invalid URL file_get_contents() returns false as it is described in documentation in here
If You are trying to get status You can simply use the solution described in other topic on this site.
<?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);
?>
Link to the mentioned topic: here
精彩评论