-1

I've an application in PHP 4.3.9 and I've a problem with SESSION. When I put a variable SESSION in an other variable, like this :

$tempInsInscription = $_SESSION['ins_inscription'];

$_SESSION['ins_inscription'] content is removed.

I don't understand why. Is a PHP4 particularity ?


EDIT

I tried many case to found where exactly I lose my content and this is in a foreach :

reset($tempInsInscription);
foreach($tempInsInscription as $key => $ins_inscription){
    if(is_array($ins_inscription)){
        reset($ins_inscription);
        foreach($ins_inscription as $key_etape => $etape){
            $_SESSION["dossier"][$key_etape]=$etape;
        }       
    }else{
        $_SESSION["dossier"][$key]=$ins_inscription;
    }
}

SOLUTION

I found a solution to solve my problem. here my new code & it's works perfectly :

$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;

reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
    if(is_array($ins_inscription)){
        reset($ins_inscription);
        while(list($key_etape, $value_etape) = each($ins_inscription)) {
            $dossier[$key_etape]=$value_etape;
        }
    }else{
        $dossier[$key]=$ins_inscription;
    }
}
LynxWeb
  • 69
  • 1
  • 9
  • There must be some other code that is affecting the seesion varibale – RiggsFolly Apr 27 '18 at 09:44
  • 1
    I am sure you know we are now on PHP7.2, but your version of PHP is probably quite toxic now. – RiggsFolly Apr 27 '18 at 09:45
  • 1
    @LynxWeb are you 100% sure you're not doing a unset at it or overwriting its data or forgetting to call session_start somewhere? With the little code provided there isn't much to go on here. – Prix Apr 27 '18 at 09:45
  • My customer don't want to upgrade this application... I change the message cause this happen in a foreach – LynxWeb Apr 27 '18 at 09:57
  • your code block doesn't show anything that indicates your claim, you need to provide us with where `$_SESSION['ins_inscription']` is manipulate/accessed and also the places its empty. My educated guess is that you might need to hire an expert to take a look at your legacy code and help you debug/fix it, if you're not able to accomplish that. – Prix Apr 27 '18 at 10:56
  • @Prix there is nothing more with this code. When I use THIS foreach, all data in $_SESSION are dropped. – LynxWeb Apr 27 '18 at 13:34
  • @LynxWeb no where in that code you're touching `$_SESSION['ins_inscription']` AFAICS aside from `$_SESSION["dossier"]` so you either missing something or something else however the lack of information about the code makes it really hard to help you. That's why I am suggesting you to find some one that can actually look at the full code to debug it. – Prix Apr 27 '18 at 15:08

1 Answers1

0

SOLUTION

I found a solution to solve my problem. here my new code & it's works perfectly :

$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;

reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
    if(is_array($ins_inscription)){
        reset($ins_inscription);
        while(list($key_etape, $value_etape) = each($ins_inscription)) {
            $dossier[$key_etape]=$value_etape;
        }
    }else{
        $dossier[$key]=$ins_inscription;
    }
}
LynxWeb
  • 69
  • 1
  • 9