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" }