简体   繁体   English

重新打开标签页(如果重新打开标签页)

[英]Reload page if tab reopened

How do I reload the page if the tab is closed and reopened in browser ? 如果关闭并在浏览器中重新打开选项卡,如何重新加载页面?

<?php
    $sql = "SELECT x FROM users WHERE id='1' LIMIT 1";
    $query = mysqli_query($connect, $sql);
    $row = mysqli_fetch_row($query);
    $x = $row[0];

    // value for x here is 50

    $sql = "UPDATE users SET x='100' WHERE id='1'";
    $query = mysqli_query($connect, $sql);
?>
<!doctype html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
        <p>Page content</p>
        <script>
            alert('<?php echo $x; ?>');
        </script>
    </body>
</html>

First the alert says 50 首先提醒说50

Then I close the tab pressing Ctrl + W 然后按Ctrl + W关闭标签

Then when I reopen the tab pressing Ctrl + Shift + T , the alert says 50 again instead of 100 然后,当我按Ctrl + Shift + T重新打开选项卡时,警报再次显示50,而不是100

What do I do to get the updated value? 我该怎么做才能获得更新的价值?

Normally if you reopen the same page within a very short time the web page will be loaded from the cache. 通常,如果您在很短的时间内重新打开同一页面,则将从缓存中加载该网页。 Try to clear the cache and reload. 尝试清除缓存并重新加载。

If you want your site to always load from the server without using the cache. 如果您希望站点始终从服务器加载而不使用缓存。 You can add the following in your php script. 您可以在php脚本中添加以下内容。 But do not use this unless this is really necessary since the caching mechanism are in place to improve the user experience. 但是除非真正必要,否则不要使用它,因为已经建立了缓存机制来改善用户体验。

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM