Epic720 Posted February 23, 2009 Share Posted February 23, 2009 I have been searching and searching online for a solution to my problem here. I have so bar been unsuccessful. I searched on here before deciding to post this. So I sincerely apologize if this problem has previously been addressed. I have an array that I am storing into $_SESSION that I create from an include file that is included in each php file. This array is to store a number of the EducationInformation class. I am using header calls to get from php file to php file. And for some reason, when returning from one page to another the class I am losing class data stored in the array. Here are some code snippets: //Save all frequently used session variables back before leaving page $_SESSION['educationCurrentInfo'] = $educationCurrentInfo; $_SESSION['educationInformation'][$educationCurrentInfo] = $educationInfo; $_SESSION['educationInformation'][$educationCurrentInfo]->address = $addressInfo; //Make sure that the session variables are getting saved before leaving page session_write_close(); //Navigate back to Education.php header('location:Education.php', FALSE); exit(0); And when creating a new: //Add one to the education count ++$educationCount; $educationCurrentInfo = ($educationCount - 1); $_educationInformations[$educationCurrentInfo] = new EducationInformation(); I have done var_dump() s all over the place to find out exactly where the data is being lost at. And it seems to be happening after one record is set just fine and you try to add a second. When the second record is added, all of the simple variables in the class get wiped. Yet, the class Address within the record stays in tact. Very weird and hard for me to track down. Does anyone have any suggestions as to how to resolve this? I really need to get over this hump! Thanks in advance~!!! Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 23, 2009 Share Posted February 23, 2009 Epic720, I use sessions all of the time and have never used session_write_close(); I did not even know what the function was, so I looked it up on php.net... " session_write_close — Write session data and end session " is the first line in the manual... It is probably the "end session" part of the function that is killing you. Just a thought. Scot L. Diddle, Richmond VA. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 23, 2009 Share Posted February 23, 2009 Make sure you have <?php session_start(); ?> as the first executable statement in each script where you are using sessions. Ken Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 In the include file that every php file includes I have a session_start(); The problem isn't losing the array altogether it is losing some of the data stored in it. More specifically all of the simple data types, not the class within the class. I have been having this problem for some time. Then I discovered session_write_close(); this solved the problem at first, when I was only adding one record to the array. Because before I was losing the data from one php file to another. Now it happens when I add another record. The newly created record gets recorded properly, but the previous record then loses it's simple data. And if I add a third record, the same thing happens to the second. And so on. This is the class I am referring to: class EducationInformation { private $schoolname = ""; private $address; private $graduated = ""; private $degree = ""; private $yearsAttended = 0; $address is a class that stores the address strings. In the constructor of this class is where I instantiate it. Everything but $address gets wiped when the new record is added. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 23, 2009 Share Posted February 23, 2009 You don't have register_globals enabled? If register_globals is enabled, weird things can happen. Ken Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 Nope. Would it help if I just showed all my code? No one has run into this issue? I'm so frustrated to understand that no one has ever had this problem... Probably something small but I really need to find the issue. Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 23, 2009 Share Posted February 23, 2009 Epic720... Post away... I will run it through my trusty Zend Studio 5.5.0 and report back.... Scot L. Diddle, Richmond VA Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 Here it is! Thank you very much!! [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 23, 2009 Share Posted February 23, 2009 Epic720, I was able to add three schools under Education... Then the Add new school button showed as disabled. ( By Design ? ) I will be out for the next 3 days, but will look again this Friday .. Scot . Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 But after adding, do the record variables stay in tact? That's the issue here. After creating a record, the previous records simple data types are wiped out. Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 Does anyone else have any insight? Quote Link to comment Share on other sites More sharing options...
Epic720 Posted February 23, 2009 Author Share Posted February 23, 2009 OK, I think this is dumb but at least I am no longer losing my variables. Maybe for some reason the session variables are not getting set before the end of each page. I added the session_write_close() at the bottom of every php file and now I am retaining my variables. I still don't know why I have to do this, and no one else does. Maybe someone can explain to me what i'm doing differently. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.