dre75230 2019-06-17 15:07
浏览 53
已采纳

如何删除多步变量会话数组

I have used the following method to eliminate the sessions of the multiple steps and even by separate variables.

if($payment === 'Completed'){
    session_start();
    unset($_SESSION['datos_form']);
    unset($_SESSION['__step__']);
    unset($_SESSION['formid']);
    unset($_SESSION['sPaso']);
    unset($_SESSION['Pending']);
    unset($_SESSION['p']);
    unset($_SESSION['step']);
    unset($step);
}

But the use of the unset function does not eliminate the steps

My PHP file where I keep the steps

<?php
    session_start();
    $step =  isset($_GET['step']) ?  $_GET['step'] : 1;
    $_SESSION['datos_form'] = $_POST;

    $datosForm = (isset($_SESSION['datos_form']) && is_array($_SESSION['datos_form'])) ? $_SESSION['datos_form'] :array();
    $sPaso = isset($datosForm['__step__']) ? $datosForm['__step__'] : 1;
    $step = isset($step) ? $step : $sPaso;
    $_SESSION['datos_form']['__step__'] = $step;

    header('Content-Type: application/json');

    $json =  array(
        'radio'     => $radio,
        'step'      => $step
    );

    echo json_encode($json);
?>

I have performed a var_dump ($ _ SESSION); and a print_r ($ GLOBALS); obtaining the following information:

[_SESSION] => Array
    (
        [datos_form] => Array
            (
                [__step__] => 3
            )

        [4b228aaae2a6a7ce403bc4ecbc481de6] => ../libro.pdf
        [cart] => Array
            (
                [0] => 11
            )

        [qty] => Array
            (
                [0] => 1
            )

        [formid] => 64da7c62c643f40684f573acffb144eba6bfaf63
        [id_user] => 1
    )

)

Using var_dump:

array(6) { ["datos_form"]=> array(1) { ["__step__"]=> string(1) "3" }

When I go to step 1, the following change is obtained [__step__] => 1 string(1) "1":

[datos_form] => Array
    (
        [__step__] => 1
    )
array(6) { ["datos_form"]=> array(1) { ["__step__"]=> string(1) "1" }

When I go to step 2, the following change is obtained [__step__] => 2 string(1) "2":

[datos_form] => Array
    (
        [__step__] => 2
    )
array(6) { ["datos_form"]=> array(1) { ["__step__"]=> string(1) "2" }
  • 写回答

1条回答 默认 最新

  • dongtuo1482 2019-06-17 15:22
    关注

    Your are unsetting __step__ as a direct descendant of $_SESSION but it is a child of $_SESSION[datos_form]

    To unset it you need to unset($_SESSION[datos_form][__step__]);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站