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
Appending GET data with form submition
Okay, what I'm trying to do is to use a form to append an already existing GET data string.
I
Where am I going wrong
Been trying to work this out for hours
I have two tables called 'Genres' and 'Films'. Genre
Concatenate two strings ???
I have string one $string1 and another $string2.
How to concatenate (add) both of them $str
Simple AND question
Hello,
I've got following code:
Code: if(strpos($row[13],"http://")
Cache PHP Objects/Classes?
Does anyone have ideas about caching PHP objects using something like: http://memcached.org/
change text color with a jQuery code
Hihow can I change the text in a asp:TextBox to a different color when I start typing using jQuery?I
Just wondering what you think about my site
I am new to phpfreaks i just seen this form and thought it would be cool to see what other thought a
have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.
Code: &
email form (cannot find the problem)
Hello there. I've been having trouble with an email form. Can't find the problem really. I've tested
Hits this week counter
I have a counter on my site that tracks hits, IP's, etc. into a mySQL database. It also includes the