在提交表单后重定向是一种好习惯吗?
问题描述:
我最近开始在我网站上的某些表单提交后(主要与购物车应用程序相关)执行 header() 重定向(到同一页面),这样用户就不会做意外的事情刷新页面或通过后退"或前进"并刷新页面.这是可以接受的做法吗?
I've recently taken to doing a header() redirect (to the same page) after certain forms on my website have been submitted (mostly related to a shopping cart application) so that the user doesn't do unintended things by refreshing the page or by going "back" or "forward" and refreshing the page. Is this an acceptable practice?
答
这是标准做法,称为 redirect after post
或 发布/重定向/获取.在处理帖子表单时,这被认为是最佳实践
This is standard practice called redirect after post
or Post/Redirect/Get. It's considered best practice when dealing with post forms