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

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题