Wamp localhost没有调用我的所有include


Wamp localhost not calling all my includes

我正试图将我的index.php分解成一个单独的块,这样我就可以编辑一个块,它会在我网站的所有页面上发生变化。

<html>
<?php include('includes/head.php'); ?>
<body>
    <? include 'includes/header.php'; ?>
    <div id="container">
        <? include 'includes/aside.php'; ?>
    </div>
    <?php include 'includes/footer.php'; ?>
</body>
</html>

然而,当我通过localhost运行此操作时,会调用head和footer,但会忽略header和side文件。

检查元件

当我将文件上传到我的webhost时,页面加载良好,包含了所有内容,所以我认为这与localhost有关?文件header.php和aside.php确实存在于includes文件夹中。

您有打字错误

<?更改为<?php

请按照以下步骤重试:

由于您使用了<? ?> PHP短标记,因此请确保在PHP.ini文件中启用了PHP短标记:

short_open_tag=On

然后重新启动Apache服务器。

其次,确保php文件的路径是正确的。有时,当前目录不是您期望的目录,例如当您包含包含文件中的文件时。我喜欢在我的includes上使用$_SERVER['DOCUMENT_ROOT'],这样我就可以从我的站点的根目录中完全引用它们:

<?php
    include($_SERVER['DOCUMENT_ROOT']."/somfolder/yourfile.php");        
?>

如果includes目录位于文档根目录之上,则可以使用..仍然从根目录引用。