Retreiving objects from Sessions
Posted on
16th Feb 2014 07:03 pm by
admin
Hi all,
I am getting really frustrated with storing and retreiving objects from a session. But it may be because of my lack of knowledge in sessions
First some system specs:
Did you know?Explore Trending and Topic pages for more stories like this.
OS - Vista Home 32bit
Webserver - IIS 7
PHP - PHP 5.2.11
php.ini
session.auto_start = 1
So, when I decide to store an object array in the session, it works just fine. I can also retrieve it from the session but with an extra attribute mentioning: "__PHP_Incomplete_Class_Name" with the value of the Object Name.
Code when I try to retrieve object from session:
Code: $hits = $_SESSION['hitsArray']; // Array of MyObject
AMethodThatDoesSomething($hits[0]); // Requires MyObject Type
And this is where it fails:
I get following information in the debugger:
__PHP_Incomplete_Class_Name | MyObject
Attribute 1 | A value
Attribute 2 | Another Value
....And so on....
Ok, so I did some research and found out objects do not work if you have "session.auto_start = 1" in php.ini
AND that you need to add following line above your session_start():
Code:
require_once("MyObject.php");
session_start();
header("Cache-control: private");
session_register('hitsArray'); // Array of MyObject
$_SESSION['hitsArray'] = $hits; // Store into session
So, I changed "session.auto_start = 0" in php.ini and added the required line above. Well then it didn't even store my object array in the session in the first place!
Now I feel that I am stumbling in the dark and hope for someone to be able to help me in my ordeal!
No comments posted yet
Your Answer:
Login to answer
246
49
Other forums
SQL query not working well
Hi,
I made a small table with 5 rows and want to make them an sql consult using rownum
How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignor
Saving data from a form into a file
Hey everybody,
Sorry, I am really new to PHP coding and such but a project kind of got thrust
Program with calculate Meteorologic measurements
Hello I'm a beginner and I want to make a program with calculate Meteorologic measurements:
ba
Adding to the next element in a multidimensional array
Hi, I'm trying to add a value to $node->field_spaces['nid'] where x is the next available spo
Can't get the unicode character
I'm trying to get some text from various parts of a file. I have converted the file to hex (bin2hex)
with clause
hi all, i have a big query that usually access the same table more than once. for example, i have s
Linkage between two scripts
Okay say I have this for a link in a script:
Code: <li><a href="#&q
mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty
Can anyone give me some link on .htaccess tutorial
i wish to have friendly url using .htaccess, but no idea yet about this
Hope that anyone cou