southofsomewhere Posted May 15, 2008 Share Posted May 15, 2008 I have a file that keeps track of ID's and how you want that ID group sorted. Essentially, I have a $_GET variable that contains a value such as: 1000.name I then take this value and explode it, to create $orgID and $sortBy. I then create a session like so: $_SESSION[$orgID] = $sortBy; It appears as if only the most recent session that was set is being displayed, as doing a dump only shows the last one set. Below is a brief overview of what I've got going. session_start(); if(isset($_GET["setorder"])) { $sortContents = explode(".", $_GET["setorder"]); $orgID = $sortContents[0]; $sortBy = $sortContents[1]; $_SESSION[$orgID] = $sortBy; } echo $_SESSION[1000]; echo $_SESSION[1001]; Assuming we go to the page with 1000.name first, and then 1001.title second.. first glance will show "name", which is correct. going to the page a second time will only show "title", ignoring the 1000. Suggestions? Link to comment https://forums.phpfreaks.com/topic/105830-php-session-variable-getting-unset/ Share on other sites More sharing options...
southofsomewhere Posted May 15, 2008 Author Share Posted May 15, 2008 Made a quick file to essentially do.. what I'm doing in a nutshell and yielding the same results. <?php session_start(); if(isset($_GET["create"])) { $sortContents = explode(".", $_GET["create"]); $orgID = $sortContents[0]; $sortBy = $sortContents[1]; $_SESSION[$orgID] = $sortBy; } echo "created sessions: <br />"; print_r($_SESSION); ?> tested via: filename.php?create=a_number.a_word Link to comment https://forums.phpfreaks.com/topic/105830-php-session-variable-getting-unset/#findComment-542432 Share on other sites More sharing options...
BlueSkyIS Posted May 15, 2008 Share Posted May 15, 2008 have you tried echo'ing $orgID and $sortBy to make sure they are the values you expect? Link to comment https://forums.phpfreaks.com/topic/105830-php-session-variable-getting-unset/#findComment-542435 Share on other sites More sharing options...
southofsomewhere Posted May 15, 2008 Author Share Posted May 15, 2008 Solution: I had to tack on text to the variable in the Session initialization for it to work.. do you HAVE to have text in the session index for some reason? E.g. $_SESSION[$orgID] = "name"; // this wont work $_SESSION['id_'.$orgID] = "name"; // this works. Link to comment https://forums.phpfreaks.com/topic/105830-php-session-variable-getting-unset/#findComment-542468 Share on other sites More sharing options...
Guardian-Mage Posted May 15, 2008 Share Posted May 15, 2008 if you have a normal variable with the same name as a session variable, it could cause this. Link to comment https://forums.phpfreaks.com/topic/105830-php-session-variable-getting-unset/#findComment-542472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.