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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大