0

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 and 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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Nibhrit
  • 188
  • 1
  • 2
  • 14
  • 1
    You have a typo in `http_respone_header` - maybe that solves the problem already? – Pekka Sep 02 '11 at 07:04
  • THIS ISNT COPY-PASTED FROM THE CODE.....the typo is only here, in the question, the code is correctly spelt. – Nibhrit Sep 02 '11 at 07:06
  • What does `print_r($http_response_header);` show? – Pekka Sep 02 '11 at 07:08
  • if i write $file=file_get_contents($url); then also i am not getting the output. its not displaying anything. i don't know what is the problem. – Nibhrit Sep 02 '11 at 07:13
  • $url contains a url retrieved from an xml file...and that has no issues, cos it is echoing the url correctly, also that url when manually entered in a browser works fine – Nibhrit Sep 02 '11 at 07:14
  • 1
    Strange, then I don't know what the problem could be. But you should definitely show your *real* copy + pasted code – Pekka Sep 02 '11 at 07:15

1 Answers1

1

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

Community
  • 1
  • 1
bariz
  • 124
  • 5