Greetings all you mega code monkeys that likes php! I want to be able to expose a session variable to multiple user(2 actually but the principle remains the same). The data storeed in the variable is an instance of an class(if that makes any difference). I have thought up one idea that might be viable: http://shiflett.org/articles/storing-sessions-in-a-database Storing the session in a database. If i have the users run a session themselves(describing user ID an so on) i can just get the user id from the users session, close down that session(and have it saved in the DB) to then fetch the session variable from the database that i want both users to be able to acess, do whatever the user wants to do with the session variable using the users ID that was sent as an argument with the function, and then shut down the "shared" session to retrieve the users own session that was recently saved. This seems kind of akward, is there any easier way to share a session variable between 2 users(and at the same time have the users employing a session of their own). Thanks for your time!
Are you trying to have 2 session ids for 2 users but also a different session parameter that is the same for the 2?
That is kind of correct virgil, but i also want the session parameter that is the same for the 2 users to actually be the same. For instance if the session variable that was shared between the 2 users was an instance of the class: "Monkey" and if user 1 called "checkMonkeyStatus()" he would in return get "Monkey is hungry". If user no 2 then called the function "feedMonkeyBannana()" followed by user 1 calling "checkMonkeyStatus()" again, user 1 would get "Just feed a bannana" in return. Meaning that they interact with the same object. This should be possible, since the sessions itself is stored on the server while the pointer to the session(cookies) is stored on the client. If i got it right, session variables dont have anything that resembles "pointers", and therefore i would have to use whole sessions in order to do this?
Why don't you store in the session just an id for the instance you want the user to have access to (such as "monkey_id" ) and do all the operations on a database. The monkey_id would work somehow like a pointer, but it might make your script a little more complicatedand you would have to make sure you syncronise everything before any operation.
The reason i dont just use the session as a pointer to a row in the database is because the object the users interact with is way to complicated for that. Unless there is some way to store an instance of an class inside a database? And regarding the synchronozation, that would only be an issue if my script was multi-threaded(disclaimer: i dont know anything about multi-threading)? Otherwise, it would be impossible for the users to make one command at the same time?
Okay so now after viewing another post on this forum i thought about this "solution": When i want to share the session variable to 2 users, i simply serialize it and store it inside a text column in my DB (maybe under some encryption), and when i want to second user to ineract with the same object as user1, ill fecth the serialized object, unserialize it, have him do whatever he wanted to do with, then serialize the object and put it back in the DB. Does that seem ok? It seems kind of uggly?