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 load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service
Multiple upload and Resize
I would like some help on my script I have the for my index.php
////
<html&
Create a form of 2 numbers input and find the greatest.
Hi, everybody.
I have a homework in my training of php, which ask you to make a form that ask
Request for tunning the below query
Hi,
Can any one help me on the below query while improving the performance,
a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header error
I'm do not know php &
Array disappearing in foreach loop
Okay, I have this problem where an array will become undefined in a foreach loop.
Here is the
mysql select query problem
how can i select multiple fields from multiple table in one query like
i have table name t1 a
Batch update record with Pagination
Hoping someone can help me with this issue I'm having, im trying to batch update records from a resu
Need PHP help... have all the elements... just need help putting them together :
Hey Guys,
I was wondering if someone could help me. I am doing a website for a client which
ctype() validation - allowing illegal characters
Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain c