donglv5269 2012-07-12 21:01
浏览 22
已采纳

如何从另一个域中提取代码

if I had several websites and I would want to read "file.html" in every website, how should I do that? The file.html would be just like this:

<h1>Hot news</h1>
<p>article</p>

I know I can use php include or require,

<? include 'file.html'; ?>

or jQuery, but only within a domain.

.load("file.html");

How should I do that cross-domain?

PS: And yes, I know that's insecure

  • 写回答

1条回答 默认 最新

  • duandongjin5647 2012-07-12 21:04
    关注

    You can use PHP for it:

    <?php echo file_get_contents('http://....'); ?>
    

    The reason why include doesn't work is that url includes are disabled by default since they are horribly insecure - the included document is handled as PHP. However, with file_get_contents no PHP code can be injected and thus it's pretty safe (except client-side things such as XSS if the remote site sends you bad JavaScript code).

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

报告相同问题?

悬赏问题

  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振