(PHP)是否在同一页面上处理表单提交更多/更少/同样处理单独页面? [英] (PHP) Is handling a form submission on the same page more/less/equally good as handling on a separate page?

查看:148
本文介绍了(PHP)是否在同一页面上处理表单提交更多/更少/同样处理单独页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP表单,我想知道如何处理提交。我记得在学习Rails时,他的行为是为表单设置一个特殊的处理页面,然后将用户重定向到一个登录页面,这将防止用户通过点击后退按钮而意外重新提交数据并返回到表单提交页面。



对于我的PHP表单,为了避免这种错误(并且为了安全起见,可能会出现这种错误),最好还是通过发送表单数据到一个处理页面,他们重定向用户?或者,只要在表单的同一页面上处理表单数据就行了?如果我做了后者,是否有可能让用户不小心通过点击/刷新/ etc等来重新提交数据?

解决方案

< a href =http://en.wikipedia.org/wiki/Post/Redirect/Get =nofollow noreferrer> Post-Redirect-Get 是为Web表单推荐的设计模式,以防止重新提交(以及您在rails中使用的内容)

提交到相同页面或不同的页面并不重要,它是防止意外重新提交的重定向。因此,您可以根据您的编码风格和/或应用程序语义来选择是发布到同一页面还是单独的页面。


I have a PHP form, and I'm wondering how I should handle submission. I remember when learning Rails that the behavior was to have a special handler page for a form, which then redirected the user to a landing page, which would prevent the user from accidentally re-submitting data by hitting the back button and going back to the form submission page.

For my PHP form, to avoid such errors (and for secureness, however it might play in) is it also best to send the form data via post to a handling page, which they redirects the user? Or would it be ok to just handle the form data on the same page as the form? If I did the latter, is it possible for a user to accidentally resubmit data via hitting back/refresh/etc?

解决方案

Post-Redirect-Get is the design pattern recommended for web-forms to prevent resubmission (and what you used in rails)

It doesn't really matter if you submit to the same page or a different one, it's the redirect which prevents the accidental resubmission. You can therefore choose whether to post to the same page or a separate page depending on your coding style and/or application semantics.

这篇关于(PHP)是否在同一页面上处理表单提交更多/更少/同样处理单独页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆