我的代码看起来像这样。
文件A.php:
Item stored in DB: <?php echo $stored_item; ?> //displays the last selected item
<form action="fileB.php" method="post" type="submit">
<input type="hidden" name="item" value="itemA">
<button>Save</button></li>
</form>
<form action="fileB.php" method="post" type="submit">
<input type="hidden" name="item" value="itemB">
<button>Save</button></li>
</form>
文件B.php:
changeItem(); ... //Changes the entries in the database, works correctly
header('Location: fileA.php');
现在数据库中的条目已更改,但 $stored_item 显示旧条目,直到我重新加载页面。
现在我想知道,如何在从文件B header('Location: fileA.php');
后自动刷新文件A.php.php
我已经尝试过这样的事情:
echo '<script>window.location.reload();</script>';
header("Refresh:0");
但是有了它们,网站就会进入一个无限刷新的循环,如果我之前使用 if 语句也是如此:
if(isset($_POST)){
echo '<script>window.location.reload();</script>';
unset($_POST);}
你可以
用PHP来做到这一点:
header("Refresh:0");
它会刷新当前页面,如果您需要将其重定向到另一个页面,请使用以下内容:
header("Refresh:0; url=page2.php");
如果您只需要刷新当前页面,则可以使用 header("Refresh:0")
。如果要刷新特定页面,则需要使用header("Refresh:0,url:$targeturl")
如果要重定向到其他页面($targeturl)。您也可以使用 header("Refresh:n");
在第 n 秒后刷新页面