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:

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 Like 49 Dislike
Previous forums Next forums
Other forums

XML Grouping
I'm using xml_parse_into_struct to get all my elements, but now I need to group them. For example, h

How to separate records and ORDER BY
Let say i have 100 records and displayed in one page, then i want to get the records from 50-100 and

php - xml what is the best way to do this.
IN essence I want to have a script calling the info from the database.. I have no problem thus far,

Remote Database Access
Hey guys!!

OK, i'm used to only working with databases from the CPANEL, accessing phpMyAdmin

Locking mysql tables with php
Hi

BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ

SWF image using php?
Hello once again.

My latest en devour requires me to produce an image of a static .swf that i

Delete all from a table
I can not get the following code to work. If I run the sql statement in the db it will delete all t

IIS7 and getimagesize() problem
I have just discovered after hrs of trying to fix a problem where it's coming from. It's to do with

Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s

User feedback after MySQL query has been executed
Hi all, I've just registered on PHPFreaks because I've got a question that I simply can't work out b

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash