You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP按时间切换显示不同按钮功能异常及旧按钮显示问题求助

Troubleshooting Time-Based Button Display Issues Across Browsers

Let’s break down the likely culprits here and walk through actionable fixes step by step:

1. Time Zone Handling Inconsistencies (Root of Chrome’s Flakiness)

Your code’s reliance on US Central Time is probably failing because it’s either using an unconfigured server time or client-side JavaScript (which is unreliable and user-dependent). That’s why Chrome behaves unpredictably.

  • Fix Step: Force PHP to use Central Time explicitly with timezone-aware code. Replace any generic time checks with this:
    // Set timezone to US Central (America/Chicago)
    date_default_timezone_set('America/Chicago');
    
    // Get current hour in 24-hour format
    $currentHour = (int)date('H');
    
    // Define the target window: 12pm (12) to 2am (2)
    $isEveningWindow = ($currentHour >= 12) || ($currentHour < 2);
    
    // Render the correct button
    if ($isEveningWindow) {
        echo '<button class="evening-btn">Your Evening Button Text</button>';
    } else {
        echo '<button class="day-btn">Your Day Button Text</button>';
    }
    
    This ensures the time check always uses the correct timezone, not server defaults or client-side time.

2. Aggressive Browser Caching (Why IE/Firefox Show Old Buttons)

The old button markup popping up has nothing to do with cookies—it’s browser caching storing outdated versions of your page.

  • Fix Steps:
    • Add cache-busting headers to your PHP script to prevent browsers from saving old content:
      header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
      header("Pragma: no-cache"); // HTTP 1.0
      header("Expires: 0"); // Proxy cache fix
      
    • If your site uses a CDN or server-side caching (like Apache mod_cache), flush those caches immediately.
    • For quick testing in IE/Firefox: Use Ctrl+Shift+R (hard refresh) to bypass cached content temporarily.

3. Leftover Client-Side JavaScript Conflicts

Old, forgotten JS might be overriding your PHP-rendered buttons—especially if the site previously used client-side time checks.

  • Check Step:
    • Open DevTools (F12), go to the Elements tab, and inspect the buttons. Watch if any JS modifies or replaces them after page load.
    • Search your codebase for any old time-based button logic and delete or disable it if it’s no longer needed.

4. Server Clock Misconfiguration

Even with correct PHP timezone settings, if your web server’s system clock is wrong, it’ll throw off the time check.

  • Verification Step:
    • Run this quick script to confirm the server’s Central Time output:
      date_default_timezone_set('America/Chicago');
      echo date('Y-m-d H:i:s T');
      
    • If the output doesn’t match current US Central Time, reach out to your hosting provider to correct the server’s system clock.

内容的提问来源于stack exchange,提问作者soulfrog

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:10:20