Re: -forgot- Storing objects in a session PHP 5.2.0
- From: "Geoffrey" <google.poster@xxxxxxxxx>
- Date: 27 Nov 2006 17:05:33 -0800
Hi Anthony --
This may turn out to be a dead end, but I have to ask anyway. :) Is
auto_start enabled for sessions in your php.ini file? If it is, this
might be putting the kibosh on your attempts to save an object to a
session variable.
Geoffrey
Anthony Smith wrote:
I have read the message boards in this group and others. I still have
not been able to pull my obect out of a session and use it. Here is how
I store it in a session:
<?
//Include the UserClass & RoleClass so that we can create a user
object.
require_once("UserClass.php");
require_once("RoleClass.php");
//This has to be the first line of code a file if sessions are used.
session_start();
//Create a new user object
$user = new User();
$user->setName($_SERVER['HTTP_OBLIX_GIVENNAME']);
$role = new Role();
$role->setSysName($xml->roles[$i]->systemName);
//Now add the role to the user object.
$user->addRole($role);
//Save the user object in the session
$_SESSION['user'] = $user;
?>
This is how I try to pull the object out:
<?
require_once("UserClass.php");
require_once("RoleClass.php");
session_start();
//Include the UserClass & RoleClass so that we can create a user
object.
//See if there is a user object in the session
if ( isset($_SESSION['user']) ){
//Get user object from session
$user = (User)$_SESSION['user'];
}
I have also just tried:
$user = $_SESSION['user'];
?>
I receive errors like these:
<b>Parse error</b>: syntax error, unexpected T_VARIABLE in
<b>/home/as411161/apache/htdocs/common/vcp_menu2.php</b> on line
<b>14</b><br />
I also get this message:
<b>Warning</b>: session_start() [<a
href='function.session-start'>function.session-start</a>]: Node no
longer exists in
<b>/home/as411161/apache/htdocs/common/vcp_menu2.php</b> on line
<b>5</b><br />
.
- References:
- -forgot- Storing objects in a session PHP 5.2.0
- From: Anthony Smith
- -forgot- Storing objects in a session PHP 5.2.0
- Prev by Date: Re: ASP.net 2.0 vs. PHP 5?
- Next by Date: When to quote?
- Previous by thread: -forgot- Storing objects in a session PHP 5.2.0
- Next by thread: Re: -forgot- Storing objects in a session PHP 5.2.0
- Index(es):
Relevant Pages
|