在关于阻止PHP表单重新提交的article中,我阅读了以下内容:
(不引用)这可能是接收表单数据的页面,例如名为“form.php”:
因此,处理POST数据的页面将被称为“submit.php”.如果登录正确,则此代码将运行:
header('Location: /login/form.php?success=true');
但是,用户无法导航到上面的URL?另外,GET变量的目的是什么?难道我不能在form.php上有一个脚本来检查用户是否已登录?
在submit.php,我应该将登录的用户名保存为$_SESSION [‘username’],然后检查form.php中是否有isset()?此外,由于其中“成功”的URL不是很漂亮,再次重定向用户是否经济?我应该使用PHP header()还是Javascript window.location.href?如你所见,我有点困惑.
谢谢你的帮助.
解决方法:
However, couldn’t a user just navigate to the URL above?
是的,他能.这不会导致任何不好的事情.
Also, what is the purpose of the GET variable?
要有一些标志代表表单已成功处理的事实,您需要祝贺用户.
Couldn’t I just have a script at form.php that checks if the user is logged in?
嗯,你可以按自己喜欢的方式保存你的代码.没有任何强烈的要求
At submit.php, should I save the logged in username as $_SESSION[‘username’], and then check if isset() at form.php?
如果你需要在当前会话中保持它 – 是的,这样做.
Also, since a URL with “success” in it isn’t really pretty, is it economical to redirect the user once again?
重定向在哪里.重定向很便宜.
Should I use PHP header() or Javascript window.location.href?
你肯定应该在PHP中这样做,否则你会遇到你试图避免PRG方式的麻烦.
标签:html,php,forms,post,get
来源: https://codeday.me/bug/20190926/1818985.html