dongwo7858 2010-12-26 08:14
浏览 18
已采纳

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 2010-12-26 22:33
    关注

    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-

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题