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.

6
  • 1
    You have a typo in http_respone_header - maybe that solves the problem already? Commented Sep 2, 2011 at 7:04
  • THIS ISNT COPY-PASTED FROM THE CODE.....the typo is only here, in the question, the code is correctly spelt. Commented Sep 2, 2011 at 7:06
  • What does print_r($http_response_header); show? Commented Sep 2, 2011 at 7: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. Commented Sep 2, 2011 at 7:13
  • 1
    Strange, then I don't know what the problem could be. But you should definitely show your real copy + pasted code Commented Sep 2, 2011 at 7:15

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.