【发布时间】:2020-08-10 06:37:21
【问题描述】:
您好,我有一个单页网站(整个网站在一页中):
/index.html
我想将该页面的页眉和页脚包裹在服务器上文件夹内的另一个页面周围:
/folder/newpage.php
(带有/index.html的页眉和页脚,但内容不同)
我已经隔离了页眉和页脚,并将它们保存在根目录中的单独文件中:
/index_header.html
/index_footer.html
如果从根目录启动,它们会正确显示,但我似乎无法将它们包含在“newpage.php”中,因为没有加载页眉和页脚内的 CSS、JS 和图像。
我尝试了以下4种方法:
include($_SERVER["DOCUMENT_ROOT"].'/index_header.html');
file_get_contents($_SERVER["DOCUMENT_ROOT"].'/index_header.html');
ob_start();
include($_SERVER["DOCUMENT_ROOT"].'/index_header.html');
$output = ob_get_clean();
echo $output;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$_SERVER['HTTP_HOST']."/index_header.html");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
但是这些方法都不起作用... 谁能帮我吗? 谢谢
【问题讨论】:
-
检查readfile()。
-
你在哪里链接到 css、js 和图像?该代码在 index.html 页面上吗?
-
也许这太容易解决了,但您是否尝试将 index.html 重命名为 index.php?大多数服务器不会执行 html 文件中的 php 代码。除此之外,我在我的简单网站中使用
include 'my_file.hmtl,它工作正常。 -
@dalelandry 正确... index.html 是带有 CSS、JS 和图像的常规 html 文件
-
@MarkusZeller 我试过了,它的行为似乎和 include() 一样
标签: php html curl include file-get-contents