Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing objects as session variables

Posted on 2008-06-19
3
Medium Priority
?
1,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.

636 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