Jump to content

get_headers() returns "HTTP request failed!"


Jabop

Recommended Posts

Code:

<?php
// www.digg.com
print_r(get_headers('http://www.digg.com', 1));

// digg.com
print_r(get_headers('http://digg.com', 1));
?>

 

 

Response:

Warning: get_headers(http://www.digg.com) [function.get-headers]: failed to open stream: HTTP request failed! in /home/jacob/workspace/tester.php on line 3

 

Warning: get_headers(http://www.digg.com) [function.get-headers]: failed to open stream: HTTP request failed! in /home/jacob/workspace/tester.php on line 6

 

Any idea why this isn't working?

Link to comment
https://forums.phpfreaks.com/topic/187505-get_headers-returns-http-request-failed/
Share on other sites

Oni-kun, if allow_url_fopen was not set to true, it would have thrown another error message explicitly stating such.

 

I found out why it wasn't working. Some sites are finicky when it comes to user agents, so I set this at the beginning of my script:

 

<?php
ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.16) Gecko/2009121601 Ubuntu/9.04 (jaunty) Firefox/3.0.16');
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.