Solved

Passing objects as session variables

Posted on 2008-06-19
3
1,196 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is my wamp get_include_path() wrong? 2 21
Wordpress Security 29 49
Ajax and PHP 9 30
show child records separated by commas 12 9
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 look for a specific file type in a local or remote server directory using PHP.

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