为什么我的PHP包含的文件更改无法反映

时间:2019-10-25 06:41:33

标签: php

我用php建立了一个网站,并创建了三个包含文件。 Header.php Footer.php 和我的内容文件。 about.php,our-services.php,contact-us.php和404.php

并在我的default.php中调用它们

<?php  include('includes/header.php');  ?>

<div id="main">

<?php
    $url = '';
    $urlX = 'includes/404.php';
if (!empty($_GET['post_slug'])) {
    $url .= 'includes/';
    $url .= $_GET['post_slug'] . '.php';
    $GetPage = $_GET["post_slug"];  // validate string!!  

    if (!file_exists('includes/' . $GetPage . '.php')) {
               include $urlX;
    }
    else{
                include $url;
            }
    }
?>

</div>

<?php include('includes/footer.php'); ?>

我的.htaccess文件是这样编码的

<IfModule mod_rewrite.c>
RewriteRule    ^pages/([A-Za-z0-9-]+)/?$    /default.php?post_slug=$1    
[NC,L]
</IfModule>

现在,我的about.php文件具有一些基本信息。 所以当我写domain.com/pages/about时,它显示了我的about.php,它可以工作:)

问题是当我在页眉或页脚或任何文件中进行更改时,我的更改未反映出来。我必须在每个页面上按ctrl + f5。如果我在domain.com/pages/about上,它将仅反映此页面上的更改,因此当我转到另一页面时,页眉和页脚将显示以前的缓存文件,因此我必须在每一页上再次按ctrl + f5看到变化。对任何包含的文件所做的任何更改都不会反映出来...请让我来解决此问题。

谢谢

我试图添加clearstatcache();像这样

<?php
clearstatcache();
$url = '';
$urlX = 'includes/404.php';

if (!empty($_GET['post_slug'])) {
    $url .= 'includes/';
    $url .= $_GET['post_slug'] . '.php';
    $GetPage = $_GET["post_slug"];  // validate string!!  

    if (!file_exists('includes/' . $GetPage . '.php')) {
               include $urlX;
    }
    else{
                include $url;
clearstatcache();
            }
    }
?>

但不起作用...

0 个答案:

没有答案