You are here: -forgot- Storing objects in a session PHP 5.2.0 « PHP Programming Language « IT news, forums, messages
-forgot- Storing objects in a session PHP 5.2.0

Posted by Anthony Smith on 11/27/06 15:22

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 />

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация