[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing objects as session variables

Posted on 2008-06-19
3
Medium Priority
?
1,219 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 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

830 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