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
timed header image rotation
I have a joomla site and I was trying to setup a rotating image based on timing NOT just refreshing
using file_get_contents??
okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and
Most basic form question ever?
Hello,
I want to use this snippet to make sure the fields in a form are ok before processing
preg_replace question
Hello!!
I hope someone can help me with preg_replace.
I load two tables from an extern
Embed Video Problem
Hey, thanks for looking!
File to be embedded:
Code: <playlist version="1&q
Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes
Connecion issue
Hi,
For some reason, I keep getting this error when trying to connect:
Warning: mysql_
Ariba 9r - SAP MM Integration
Hi experts,
The standard Ariba adapter for 9r creates a relationship between Cost Centers
Not showing whole name with mail () script
I sent up a simple mail form with the PHP mail() script. One problem is when it sends an email with
Filename and Line Number Custom Error
I have a class, with a method that accepts 2 parameters. I would like to output error messages.