is it a good idea to put a class object into a session cookie?
[php]
$_SESSION['ClassOne'] = new ClassOne();
[/php]
You can do that, but you need to include the file that defines the class before calling session_start()
Thanks just check it's safe to do just, because I'm having trouble including all the classes making them work with each other.
I would suggest there is an issue with how you've written or are including your classes then.
At the moment I'm using this function to load the classes in, its a working progress.
[php]
public function __construct(){
if(is_dir(LIBROOT)) {
$dh = opendir(LIBROOT);
while($file = readdir($dh)) {
$frag = explode(".", $file);
if($frag[1] == "database" && $frag[0] == DB_CON_TYPE && DB_CON_TYPE == "pdo") {
include $file;
$_SESSION['database'] = new database(DB_SOURCE,DB_HOST_IP,DB_USER,DB_PASS);
}
if($frag[1] == "class" && $frag[0] != "core") {
include $file;
$_SESSION[$frag[0]] = new $frag[0]();
}
}
} else {
echo "<b>ERRORL:<b> libary directory can not be found.";
closedir($dh);
}
}
[/php]
That's some fairly messy code.
Also, don't store the db connection in the session.
Yeah, a DB connection probably won't work in a session since it can't really be serialized and deserialized without breaking the connection.
[QUOTE=Siemens;26412685]Yeah, a DB connection probably won't work in a session since it can't really be serialized and deserialized without breaking the connection.[/QUOTE]
Thank but your advice can to late, had to look in a text book to find that out. XD
Sorry, you need to Log In to post a reply to this thread.