簡體   English   中英

在緩存的頁面上顯示PHP時間戳

[英]Show PHP timestamp on cached page

我正在使用我的標題橫幅中包含一個PHP代碼段

<?php include ('/time.php'); ?>

這是我從另一篇SE帖子中獲得的代碼:

<?php
    date_default_timezone_set('America/Chicago'); // timezone 

    $weekday = date(l); // today
    // print $weekday; // Debug
    // print date("H:i"); // debug

    // Set open and closing time for each day of the week
    if ($weekday != "Saturday" || $weekday != "Sunday") {
        $open_from = "07:00";
        $open_to = "24:00";
    }

    // now check if the current time is before or after opening hours
    if (date("H:i") < $open_from || date("H:i") > $open_to ) {
        print "House: We're closed for the day.";
    }

    else {
        print "Hours: We're open!";
    }
?>

直接在瀏覽器中查看time.php時,它可以正常工作,但是在主頁上,看起來好像緩存系統正在緩存文件生成的最后一條消息。 例如,它將無限期地顯示“我們已關閉”,直到我清除服務器上的緩存頁面為止。

我必須重新設計此方法以使用AJAX嗎?

還是將jQuery函數實現它,還是像PHP代碼段的結果一樣簡單地對其進行緩存?

嘗試

add_filter( 'wp_headers', $headers ) function() {
    return array_merge( $headers, wp_get_nocache_headers() );
} );

這將添加no緩存頭:

'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
'Last-Modified'] = false,

到要發送的HTTP標頭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM