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
how to validate date using javascript
I need to validate date in textbox using javascript..
The date is must be not greater than TODAY
How to read posted binary data from a mobile device and post it to a web server?
Here is the senario...
I have a mobile device (MD) that posts binary data to a Web Server (WS
Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what th
Help with simple query
Hi,
I'm trying to do a Query with a Union where I want to print the number of rows $tc conta
Linked Keywords
I am trying to get a script that makes my predefined keyword converted to links and / or converted t
Server side $_SESSION
how does one keep the session completely server side. no cookies to the browser at all. i need this
Pagination
Hi All,
I think I'm finally getting somewhere with pagination!
I can now submit a quer
date("now") prints out wrong date ?
Hi Guys
Anyone know why and how I can fix it ?
How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:
values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data