我是php的初学者,试图创建一个包含页眉和页脚的main.php文件
<html>
<body>
<div class="header">
logo, navigation etc
</div>
<div class="footer">
Footer content here
</div>
</body>
</html>
<?php include "header.php"; ?>
<div class="main content">
<h1> header </h1>
<p> paragraph </p>
</div>
<?php include "footer.php"; ?>
Warning: include(header.php): failed to open stream: No such file or directory in - on line 1
Warning: include(): Failed opening 'header.php' for inclusion (include_path='.:') in - on line 1
Warning: include(footer.php): failed to open stream: No such file or directory in - on line 6
Warning: include(): Failed opening 'footer.php' for inclusion (include_path='.:') in - on line 6
所有文件都在同一个文件夹中并在XAMPP上进行
答案 0 :(得分:1)
您所包含的任何文件都必须位于include_path。请致电get_include_path查看当前值。
答案 1 :(得分:0)
您应该将文件添加到同一文件夹中,以便它们位于同一父目录中,然后您可以使用“ include”直接访问它们,例如:如果我创建了第三个文件,则在名为Home的文件夹中有2个php文件我可以使用此代码“ <?php include'找到另外两个文件之一的名称。php'希望它清楚
答案 2 :(得分:0)
如果页眉,页脚和主文件位于同一目录中,请尝试以下操作:
include dirname(__FILE__) . '/header.php';