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
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');
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.