【问题标题】:My index.php file is showing all pages on my site at once我的 index.php 文件同时显示我网站上的所有页面
【发布时间】:2016-01-10 17:16:12
【问题描述】:

我正在使用 index.php 文件在我网站上的所有页面上包含页眉、导航和页脚,但是我的 php 出现问题,它一次显示 pages 文件夹中的所有页面,而不仅仅是显示我当前所在的页面。

这是我正在使用的 PHP,任何建议将不胜感激!

<?php
$files = scandir( __DIR__ . '/pages' );

unset( $files[0] );
unset( $files[1] );

foreach($files as $file){
    include __DIR__ . '/pages/' . $file;
}
?>

【问题讨论】:

  • 您正在使用 scandir 获取所有页面的列表。然后遍历列表并将它们全部包括在内。不确定你期望发生什么?你如何确定你在哪个页面上?
  • 它完全按照你的吩咐去做。
  • 嗯,它不仅包括,它还执行你的脚本。

标签: php web indexing


【解决方案1】:

然后只需删除整个脚本并使用&lt;?php include('yourDesiredfile.php'); ?&gt; 来处理您想要包含的文件。

【讨论】:

    猜你喜欢
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 2011-02-13
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多