Solved

Passing objects as session variables

Posted on 2008-06-19
3
1,195 Views
Last Modified: 2010-05-18
It's my understanding that I can pass objects around during a session by simply assigning them to a session variable, as long as the class is defined before I run session_start().  That said, I'm having problems finding the right solution.  I'm trying it the way I've described above, as well as serializing/unserializing and then passing into/out of session variables.  What might I be doing wrong?
<?php
 
// include Timecard class definition
require("Timecard.php");
 
session_start();
 
if($_SESSION['logged_in_userID']) {
	$tc = new Timecard($_SESSION['logged_in_userID'],"");
        // setup page header -- removed for clarity
	// display timecard -- removed for clarity
	$_SESSION['currentTimecard'] = $tc;
} else {
	// create a new timecard -- removed for clarity
}
 
?>

Open in new window

0
Comment
Question by:TechComposer
  • 2
3 Comments
 
LVL 2

Author Comment

by:TechComposer
ID: 21825453
To follow is the script in which I'm attempting to reload this object.  When calling "print_r($_SESSION)", I am given:

Array ( [logged_in_userID] => 1 [logged_in_admin] => 1 [currentTimecard] => Timecard Object ( [userID:private] => 1 [date:private] => 2008-06-19 11:21:53 [timecardID:private] => 252 [timecardClosed:private] => 0 [timecardActivities] => Array ( ) ) )
<?php
 
require("Timecard.php");
 
session_start();
 
if($_SESSION['logged_in_userID']) {
	// setup page header -- removed for clarity
	
	$tc = $_SESSION["currentTimecard"];
	echo "User ID: " . $tc->getUserID . "<br>";
	echo "<h3>Session Variables:</h3>";
	print_r($_SESSION);
}
 
?>

Open in new window

0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 21825480
I think you are missing two anchors:

Have you tried using  $tc->getUserID() instead of $tc->getUserId ?

Kind regards

-r-
0
 
LVL 2

Author Comment

by:TechComposer
ID: 21825642
Well, don't I look like a moron...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question