I've managed to have a class in session and it actually wasn't any problem.
Example: (index.php and global.inc.php)
global has the functions I call, and also includes the class I use.
index.php
<?
include($DOCUMENT_ROOT."/inc/global.inc.php");
dbConnect(); //connects to db
getSession(); //startsess() and sessid()
getDefaults();//globals some vars
//The page then has a login form and here's the login stuff:
if ($todo == "login") {
if (login($user_name, $password)) {
header("Location: $HTTP_REFERER");
exit();
}
}
if(checkSession()) {
$oUserUnserialized = unserialize($oUserSerialized);
echo $oUserUnserialized->user_id;
echo $oUser->getUserId();
} else {
echo "we don't have a session";
}
?>
Global.inc.php
<?
function getDefaults() {
global $oUser, $oUserSerialized;
}
The login function does some db accessinn and then:
$oUser = new User;
$oUser->setUserId($user_id);
$oUserSerialized = serialize($oUser);
session_register("oUser");
session_register("oUserSerialized");
getSession() {
session_start();
session_id();
}
checkSession just returns true if session_is_registered("some variable")
?>
So if you use serialize, then you don't have access to functions in the class. But you can access functions in the class if you don't serialize.
I didn't have no problems. I'm running this on Linux, Redhat with Php 4 or 4.01