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

Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi

session variables not working anymore
hello,
i use sessions to handle authentication within my site. my host has been changing a lot of

problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php

<?php
funct

Undefined Index Notice In Internet Explorer Only
I am getting the following notice:

QuoteNotice: Undefined index: jrox in /home/ycsn/public_h

EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t

[RESOLVED] Socket/Port remains open after app crashes
I'm having this problem with a networked app in vb.net.

If the program exits normally the por

Windows 7
Windows 7 default user account control worries experts. Corporate IT departments should be pleased w

Call to undefined function mysql_fetch_accoc()
New to php/mysql coding. What's wrong with this sequence, or am I
just not seeing to obvious?

Need help making a blockquote and line items conditional
I have some code I bought a few years ago that allows my clients to update content on their site usi

pointer 102 question
I read a book
1
2
3
4
5
6
7
8
9
10
11
12
int main() {

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