fopen() unable to open some URLs?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I've used fopen() extensively to open web pages. I've found that there is a
small minority
of web pages that open fine in a browser, but are inaccessible using
fopen(). Here are
two such URLs:

For example, using the code below, almost every web page that will open in a
will be read correctly by this code. There are few exceptions, such as the
above URLs.
I'm wondering why/how could a page be accessible to a browser but not to

Here's the code:


$page = "";

if (isset($url))
  $fp = fopen($url, 'r');

  if ($fp != false)
    while (feof($fp) == false)
      $page .= fread($fp, 10000);


    echo "URL: $url =====================================<br><br>";
    echo $page;


I have this code running with a simple form interface here:

Any ideas?

Thank you,


Re: fopen() unable to open some URLs?

Michael Ferrier wrote:
Quoted text here. Click to load it

Some websites require an explicit user-agent header in order to return a  
response, as is the case with

There are several ways to include the user agent, of which the easiest is to  
apply the ini_set function as follows:

$fp = fopen(' /','r');

When you run this code, you will see it works fine for Bare in  
mind that this doesn't work for sites which require more then a user agent  
string to operate.


Site Timeline