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__]);

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

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的