表单提交后未设置发布变量 [英] Unset post variables after form submission

查看:71
本文介绍了表单提交后未设置发布变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做到以上几点?基本上,我不希望再次提交表单,如果有人已经提交了一次表单之后按了刷新.在这种情况下,浏览器会询问您是否要再次提交表单.这种情况下unset($_POST['username'])对您有帮助吗?

Is there a way to do the above? Basically, I don't want the form to be submitted again if someone presses refresh after already submitting the form once. In which case the browser asks, do you want to submit the form again. Will unset($_POST['username']) be of any help is this case?

推荐答案

post/redirect/get是一个不错的选择,因为一些张贴者已经提到过.

The post/redirect/get is a good option as some posters have already mentioned.

我可以想到的另一种方法是在dostuff.php页面中设置一个会话,以指示发布已经完成.每次检查此会话变量,以查看是否由于刷新页面而再次加载页面.

One another way I can think of is to set a session in the dostuff.php page to indicate that the posting has already been done. Check this session var each time to see if the page is being loaded again because of a page refresh.

<?php
    session_start();
    if(isset($_SESSION['indicator'])) 
    {
        /*
        dont do anything because session indicator says 
        that the processing was already done..

        you might want to redirect to a new url here..          
        */
    }   
    else
    {

        /*
        first set session indicator so that subsequent 
        process requests will be ignored
        */
        $_SESSION['indicator'] = "processed"; 

        //process the request here..
    }
    ?>

在您重定向到的页面中,取消设置会话变量,以便可以重新提交表单,使其成为新的发布操作.这将允许新的表单发布,但会由于页面刷新而阻止发布操作

In the page you redirect to, unset the session var so that the form can be resubmitted again afresh, making it a new post operation. This will allow new form posts but will prevent post operations due to page refresh

这篇关于表单提交后未设置发布变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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