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 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题