如果页面重新加载,PHP $ _POST表单将过期 [英] PHP $_POST form to expire if page reloaded

查看:99
本文介绍了如果页面重新加载,PHP $ _POST表单将过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单(对于A)重定向到另一个表单(表单B)。

当用户重定向到B时,如果设置$ _POST,将触发电子邮件功能。如果用户重新加载页面,这是一个问题b / c,这封电子邮件被再次发送。



如果页面是真实的,我想停止发送电子邮件。

因此,我在表单A中包含了一个字段,其中type = hidden与value = send,并且当发送电子邮件(表单B)时,我取消设置此字段,但如果

  if(isset($ _ POST ['emailtrigger'])){

emailfunction();
unset($ _ POST ['emailtrigger']);


}

我该如何提示页面

谢谢

解决方案

如果您想要避免重定向,或者希望保护自己免受按返回并在重定向后重新提交表单的用户的帮助,那么简单的解决方案就是添加一个带有随机值,当表单加载时生成。表单提交后,只需将该字段值写入会话数据。然后,如果用户提交相同的表单数据,您将比较随机字段和会话数据中写入的内容。如果有这样的价值 - 你不会处理表单数据。


I have a form (for A) that redirects to another form (form B).

When the user is redirected to form B, the if $_POST is set, an email function is triggered. This is a problem b/c if the user reloads the page, this email is sent again.

I would like to stop sending the email if the page is realoaded.

Hence, I included a field in form A, type=hidden with value=send, and when the email (form B) is sent I unset this field, but if I reaload the page the email is sent anyway.

if(isset($_POST['emailtrigger'])){

            emailfunction();        
    unset($_POST['emailtrigger']);


  }

How could I cue to the page that after the email has been sent, if page (form B) is reloaded, to skip email function?

Thank you

解决方案

If you want to avoid redirects, or want to protect yourself against users that press "Back" and resubmit the form after redirect, simple solution would be to add a hidden field with a random value, generated when form if loaded. After form submit, just write this field value into session data. Then, if user submits same form data you will compare random field and what is written in the session data. If there's that value - you don't process the form data.

这篇关于如果页面重新加载,PHP $ _POST表单将过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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