php - some of session varibles gets back to the old value -
i use centos 6.6, php 5.3.4
i have php script called in iframe(let's call a.php).. when it's called a.php?p_type=1&item_num=1234, saves array session. sometimes, merges 2 array in session , save session again merging doesnt work.. here simplified code. (i hide minor details brevity)
header('p3p: cp="cao psa our"'); session_start(); $p_type_val = $_get["p_type"]; $sess_var = "a".$p_type_val; $some_array = $_session[$sess_var]; if(isset($_get["item_num"]) { $some_array[] = $_get["item_num"]; $_session[$sess_var] = $some_array; } if($p_type_val == 1) // when p_type 1, merge 2 arrays in session. { $sess_var2 = "a"."2"; $some_array2 = $_session[$sess_var2]; $_session[$sess_var2] = array_merge($some_array,$some_array2); } else if($p_type_val == 2) { $some_array2 = $_session["p2"]; print_r($some_array2); } .........
first, called a.php?p_type=1&item_num=1234, called a.php?p_type=2 lator, newly added item number 1234 "a2" lost. values in array "a2" old values. values in "a1" no problem.
i checked session file in /var/lib/php/session directory , found result expected. after called a.php?p_type=1, values in file expected. right after a.php?p_type=2, values go old ones.
the funny thing when call a.php?p_type=2 twice diffrent item_nums, array "a2" works correctly.
i don't know why values in session go old values. should start debugging this..
any suggestion appreciated..
i guess problem don't read manual it, no rudeness intended there when merge 2 arrays can happend, explain 'whys' of it, because of suggest read stuff entirely, no kittin, there overlapping examples explained in section of examples of manual too, , explain how avoid/use "problem".
it textualy says: "if input arrays have same string keys, later value key overwrite previous one. if, however, arrays contain numeric keys, later value not overwrite original value, appended."
so, using same string values in both $_session variables, or both of them have same int index data, told you, necesary see creation of $_session, otherwise cant see compositions of arrays merging and, because of that, can't suggest 1 way solve problem oriented necesitys.
which, in fact, not saying, merging 2 $_session variables not saying why for, , taking in perspective, rest of people cannot know if right aproach want.
anyway, solution read part of manual & instanciate code.
http://php.net/manual/en/function.array-merge.php
have day
Comments
Post a Comment