i want to have a variable that has the same value for all the different users/clients accessing the system.
also the variable's value has to be modifiable.
like if any one user changes the value, the change has to get reflected to all other users too.
This will ensure that we can safely access the variable defined in other page, by just using $_SESSION['name']. In printName. php file, echoing the session name variable prints the name we have inputted from user in another page. So, this is how you pass variables and values from one page to another in PHP.
To set session variables, you can use the global array variable called $_SESSION[]. The server can then access these global variables until it terminates the session. Now that you know what a session is in PHP and how to start one, it's time to look at an example and see how it works.
Session variables on the client are read-only. They cannot be modified.
The session is unique to whomever has that session ID, which is determined by the cookie. Yes, it's unique to each user. Variable scope means nothing here. Each request handled by PHP is isolated and has its own global scope (unless you have built your own daemon or something).
Store the variable in a shared space like
A file
A database record (easiest for implementing locking, see below)
A memcache bucket
you can easily modify it there. You may need to use some sort of locking mechanism to prevent race conditions when multiple users try to edit the value at the same time.
Just use a database table for storing that value.
That's the simplest way to store persistent application-wide data in a Web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With