Jabop Posted January 6, 2010 Share Posted January 6, 2010 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 More sharing options...
oni-kun Posted January 6, 2010 Share Posted January 6, 2010 Is allow_url_fopen set to true within your php.ini? If not the function will fail right away. Link to comment https://forums.phpfreaks.com/topic/187505-get_headers-returns-http-request-failed/#findComment-990035 Share on other sites More sharing options...
Jabop Posted January 7, 2010 Author Share Posted January 7, 2010 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'); ?> Link to comment https://forums.phpfreaks.com/topic/187505-get_headers-returns-http-request-failed/#findComment-990043 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.