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
Connect to database that isn't localhost
I am currently doing a small script for a company that doesn't have mySql support on there hosting.
Problem with the Update command used with a sqldataadapter
I'm connected to a database on an SQL Server and I'm using a sqldataadapter, sqlconnection, sqldatas
what are '%S%', '%E%'
for example when i see Code: [Select]printf("Hello %srn", $name);
what does %s means
How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g
Code error with Index.php
Error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/runevid/public_
Program with calculate Meteorologic measurements
Hello I'm a beginner and I want to make a program with calculate Meteorologic measurements:
ba
login page does not execute a else statement
I've created a login page using sessions.
When an incorrect user name or password is entered then
getAlexaRank($url) function not working
I have made a function to get alexa rank
the site is here: http://mytestsite.rack111.com/1
Help pulling in 'id' with "read more" link
I'm trying to create snippets of my articles in the cms I'm creating, and then have them redirect to
Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then