php 允许用户在没有“确认表单重新提交”弹出窗口的情况下刷新浏览器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2414660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:22:57  来源:igfitidea点击:

Allowing users to Refresh browser without the "Confirm Form Resubmission" pop-up

phphttp

提问by John

I have a login system, and while logged in, if I refresh the browser, Chrome shows a pop up window titled "Confirm Form Resubmission." I assume that the same thing would happen with other browsers.

我有一个登录系统,在登录时,如果我刷新浏览器,Chrome 会显示一个名为“确认表单重新提交”的弹出窗口。我认为其他浏览器也会发生同样的事情。

How can I allow the browser to be refreshed without this confirmation pop-up window? Of course, I would also like to stay logged in while refreshing the browser.

如何在没有此确认弹出窗口的情况下刷新浏览器?当然,我也想在刷新浏览器的同时保持登录状态。

回答by Tyler Carter

After processing the POST page, redirect the user to the same page.

处理 POST 页面后,将用户重定向到同一页面。

On http://test.com/test.php

http://test.com/test.php

header('Location: http://test.com/test.php');

This will get rid of the box, as refreshing the page will not resubmit the data.

这将摆脱该框,因为刷新页面不会重新提交数据。

回答by Sean Fisher

Alright, so at the top of you login page, you can just have this:

好的,所以在您登录页面的顶部,您可以拥有以下内容:

<?php
if (isset($_POST['username'])) {
// Do you login stuff here....

if ($passed == true) {
    header('Location: index.php');
} else {
    echo "Invalid username/password!";
}