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
49
Other forums
Big Problem!! Please help
Hi Guys,
Im making a website for a friend have encountered a really annoying problem. When ev
PHP Code / Script To check weather the given email exists in a domain
Hi,
I want to implement the following in my web page
in sign up we will ask to enter u
PHP Mysql Staff Induction System
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi
Prevention Help
How can I use PHP or any other language (feel free to move this thread) to prevent users doing scree
Form Help
Here is the form:
Line number On/Off | Expand/Contract<? include("../include/sess
Timer control causing error
I recently decided to add a timer control to an existing page that uses AJAX on my site. As soon as
Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag
Mail form doesn't send Russian/Cyrillic characters correctly?
When someone enters foreign characters (like Cyrillic text, and Japanese/Chinese probably gives the
Get content from table into a list, without repeating.
Alright this is kinda an odd thing, so I need some help.
I have a table "quote" wit
How to restrict the display of report variants
Hello All,
I want t know how to restrict the display of report variants.
I mean, whe