View Full Version : Shared/Global Session variable

12-01-2010, 08:53 PM
Is it possible to have a session variable that is shared between different users sessions?

As an example, is it possible to declare something like this:


User 1 Session
echo $_SHARED_SESSION['todays_color']; //outputs: red

User 2 Session
echo $_SHARED_SESSION['todays_color']; //outputs: red

12-01-2010, 09:15 PM
I think you're overcomplicating it. Effectively the same thing can be achieved by saving data in a database or file, but use a function to read and set the value so your code doesn't bloat too much. You can link the sessions to the database entry or file by setting a session variable for each relevant user.

12-02-2010, 07:54 PM
Thanks, I was trying to avoid that using a mysql query for that. I may use an include.

Any advice about whether using includes vs mysql queries is less taxing on server resources?

12-02-2010, 08:56 PM
Actually, includes should be substantially faster and less server intensive overall... It's just a ***** to manage properly. Databases, for all their overhead, are gold for management.