drwf69817 2014-01-27 10:31
浏览 17
已采纳

从POST获取转储php变量

I have some PHP code running at the top of my page

if(isset($_POST['arrow1']) and isset($_POST['arrow2'])) {....}

And a form that sends data to this page. What i want to do is to empty the variables once the php code at the top runs so that on refresh it won't run again.

How can i achieve that?

Thank you

  • 写回答

3条回答 默认 最新

  • dougaoshang0237 2014-07-28 04:57
    关注

    I know the question is a little bit outdated but....

    Your form will run only once... or everytime... depending on how you load the page. If the form submits POST, unsetting is kind of sinceless. Let´s say the form on the top says: Push button and submit "hello world". You push the button, page get´s load (and since you dont use ajax, it has to load new), "hello world" is submitted and after submit POST get´s unset. Form is still there.. you press button again... same thing happens again. To avoid this you propably have to use $_SESSION

    Sample

    if((!isset($_SESSION['arrowsWasSet'])) 
    {
        if(isset($_POST['arrow1']) and isset($_POST['arrow2']))
        {
            unset($_POST);
            $_SESSION['arrowWasSet'] = true;
        }
    }
    

    other way is to store data into the session and check if its already set to session.

    if(isset($_POST['arrow1']) && isset($_POST['arrow2'])) 
    {
        if(!isset($_SESSION['arrows']))
        {
            $_SESSION['arrows']['arrow1'] = $_POST['arrow1'];
            $_SESSION['arrows']['arrow2'] = $_POST['arrow2'];
        }
        unset($_POST); 
        //you can call this to get a clean post everytime, but no need.
    }
    

    do you have a type in there ? i mean shouldnt this mean array1 instead of arrow1 ? :)

    anyways, $_SESSION survives the refresh. So after refreshing the page, you can still check if something happend. To empty session you could do:

    • session_destroy (kills hole session)
    • restart your Browser (not refresh, totaly restart! kills hole session)
    • hitting keys ALT + F5 (kills hole session)
    • clear Browsercache manualy (kills hole session)
    • $_SESSION['xy'] = NULL; (kills parts in session)
    • unset($_SESSION['xy']); (kills parts in session)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?