I have a page which is a navigation and displaying sytem for picture galleries. I try to store some arrays in session variable...works perfectly fine with integers bur I have tried many ways for string and none worked...(I use a mysql class to retrive date from the database but it has no influence on my session problem)

here is the code :

<? require_once($_SERVER['DOCUMENT_ROOT']."/_inc/db.Class.php"); ?> 
<? require_once($_SERVER['DOCUMENT_ROOT']."/_inc/config.inc.php"); ?> 
<? 
if (!isset($level)) 
{ 
$level=0; 
} 
$new_level=$level+1; 
if (!isset($parent)) 
{ 
$parent=0; 
} 
if ($level!=0) 
{ 
session_start(); 
$till=$level+1; 
$db->sql = "SELECT nom FROM img_cat where id=".$parent; 
$q_res_top = $db->fetch_array($db->sql); 
if($q_res_top) 
{ 
$titre=$q_res_top['nom']; 
if ($level>1) 
{ 
for ($i=1;$i<$level;$i++) 
{ 
$array_id[$i]=$_SESSION["id"][$i]; 
$array_niv[$i]=$_SESSION["niv"][$i]; 
//I tried this solution with $_SESSION ["titre"] but it didn't work 
} 
} 
$array_id[$level]=$parent; 
$_SESSION["id"]=$array_id; 
$array_niv[$level]=$level; 
$_SESSION["niv"]=$array_niv; 
$array_titre=array("galerie"); 
if (isset($_SESSION["titre"])) 
{ 
array_push($array_titre,$_SESSION["titre"]); 
} 
$array_titre[$level]=$titre; 
$_SESSION["titre"]=$array_titre; 
} 
} 
?> 
<html> 
<head> 
<title>DYNAM GALERIES</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
<? 
if ($level!=0) 
{ 
?> 
<a href="<? echo $PHP_SELF?>";">galerie</a> | <? for ($i=1;$i<$till;$i++){echo "<a href='".$PHP_SELF."?level=".$_SESSION["niv"][$i]."&parent=".$_SESSION["id"][$i]."'>".$_SESSION["titre"][$i]."</a> | ";}?> 
<? 
} 
?> 
<table width="100%" cellpadding="5"> 
<? 
$db->sql = "SELECT * FROM img_cat where id_parent=$parent AND (child='y' OR galerie='y')"; 
$q_res = $db->query($db->sql); 
if($q_res) 
{ 
for($i = 0; $i < sizeof($q_res); $i+=2) 
{ 
?> 
<tr> 
<? 
$end=$i+2; 
for($j=$i;$j<$end;$j++) 
{ 
?> 
<td><? if ($end>sizeof($q_res) AND $j==$end-1){echo " ";}else { echo "<a href=\"".$PHP_SELF."?level=$new_level&parent=".$q_res[$j]['id']."\">".$q_res[$j]['nom']."</a>";}?></td> 
<? 
} 
?> 
</tr> 
<? 
} 
} 
else 
{ 
echo "<tr><td cospan='2'>la base est vide</td></tr>"; 
} 
?> 
</table> 
</body> 
</html> 

here is an exemple of the code that is generated : 
<html> 
<head> 
<title>DYNAM GALERIES</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
<a href="/galerie.php";">galerie</a> | <a href='/galerie.php?level=1&parent=45'>test</a> | <a href='/galerie.php?level=2&parent=46'></a> | <a href='/galerie.php?level=3&parent=48'>test</a> | <table width="100%" cellpadding="5"> 
<tr><td cospan='2'>la base est vide</td></tr></table> 
</body> 
</html> 

?>  

as you can the see the array with integers are stored perfectly in session variables but it doesn't work with strings

Can somebody help???I am desperate...

    thanks for your answer but could you be more specific...I don't know how to use this function

      Read the manual... by clicking on the link.

        $_SESSION['array in session'] = serialize($array);
        $array = unserialize($_SESSION['array in session']);

          thanks everyone, I'll try this tonight

            I tried the solution with the function serialize() but it didn't work...

            I found another way to do : by storing each string in a different session variable and using a variable for the session variable name like this :

            $_SESSION["titre".$level]=$titre;

            but I still would like to find a way to store an array in a session variable and add a new field each time the page loads. So, if anyone has an example code for this purpose, could you post it please????

            I know my english is not good. To explain my problem in a simplier way, I need something that works almost like a shopping cart, something that implements the url variables (variables can be strings) to an array...

              Coul you post the code for how you used serialize(), because it should work 😕

                Here is the code I tried :

                <?  
                if (!isset($level))
                {
                $level=0;
                }
                $new_level=$level+1;
                if (!isset($parent))
                {
                $parent=0;
                }
                if ($level!=0)
                {
                session_start();
                $till=$level+1;
                $db->sql = "SELECT nom FROM img_cat where id=".$parent;
                $q_res_top = $db->fetch_array($db->sql);
                if($q_res_top)
                {
                $titre=$q_res_top['nom'];
                if ($level>1)
                {
                for ($i=1;$i<$level;$i++)
                {
                $array_id[$i]=$_SESSION["id"][$i];
                $array_niv[$i]=$_SESSION["niv"][$i];
                //I tried this solution with $_SESSION ["titre"] but it didn't work }
                }
                $array_id[$level]=$parent;
                $_SESSION["id"]=$array_id;
                $array_niv[$level]=$level;
                $_SESSION["niv"]=$array_niv;
                $array_titre=array("galerie");
                if (isset($_SESSION["titre"])) { $array_titre=unserialize($_SESSION["titre"]); } else { $array_titre=array("galerie"); } $array_titre[$level]=$titre; $_SESSION["titre"]=serialize($array_titre); }
                }
                ?>

                  I also tried this

                  $array_titre=array(unserialize($_SESSION["titre"]));
                  
                    Write a Reply...