如果页面重新加载,PHP $

编程入门 行业动态 更新时间:2024-10-28 00:15:14
本文介绍了如果页面重新加载,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 $

本文发布于:2023-11-24 22:33:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   页面   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!