dongwo7858
dongwo7858
2010-12-26 08:14

PHP - file_get_contents系统错误?

已采纳

I'm trying to parse the html from a url. I do this:

$html = file_get_contents($someURL);
echo $html;

But when I run that script, the page shows this:

UISCGI (software8a-web; software8a-link):
This site is best viewed with Netscape 4.6 or 4.7 or Internet Explorer 5 and greater.
At this time Netscape 6 is not supported for Link usage.

I also tried CURLing the url, while faking IE7 as the User Agent.

What's going wrong here? I couldn't find this error anywhere with Google. How do I get past this system error?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanpasi6287 duanpasi6287 11年前

    I found such an adress, faking of the user-agent works fine. Maybe the setting of the header is wrong in your case.

    simple example:

    <?php
       //fake IE6
      ini_set('user_agent', "Mozilla/4.0 (compatible; MSIE 6.0)
    ");
       //request
      echo file_get_contents('http://www.bu.edu/link/');
    ?>
    

    (without the ini_set() I get the same output like you)

    Note: From PHP5 on file_get_contents() also allows setting of headers via the optional context-parameter-

    点赞 评论 复制链接分享

相关推荐