This is a discussion on How to share a variable between browser sessions within the PHP Language forums, part of the PHP Programming Forums category; I have to share a variable between browser sessions. One session for example changes the variable, the other sessions must ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have to share a variable between browser sessions.
One session for example changes the variable, the other sessions must see the changes (get the new value instead of the original value) it's not allowed to save the value in a database or to save it into a file. It must be a kind of global server variable, changeable by every session. tia |
|
|||
|
You could use an environment variable ($_ENV['foobar'])
Ikke wrote: > I have to share a variable between browser sessions. > One session for example changes the variable, the other sessions must > see the changes (get the new value instead of the original value) > it's not allowed to save the value in a database or to save it into a > file. It must be a kind of global server variable, changeable by every > session. > > tia |
|
|||
|
tintub@gmail.com wrote:
> Ikke wrote: >> I have to share a variable between browser sessions. >> One session for example changes the variable, the other sessions must >> see the changes (get the new value instead of the original value) >> it's not allowed to save the value in a database or to save it into a >> file. It must be a kind of global server variable, changeable by >> every session. There are shared memory functions in PHP which may be able to accomplish what you are after: http://www.php.net/manual/en/ref.sem.php But other than that (if the above functions do not work) you can't do this without saving it into some sort of state file or database table. Is there any reason you don't want to do this? The problem with non persistant data that is only stored in memory is that if the web service or server is restarted then you're going to lose whatever the current value is. > You could use an environment variable ($_ENV['foobar']) That wouldn't hold from page to page. Whatever you set in $_ENV will only last for the duration that the page is parsed. -- Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/ |
|
|||
|
hi tia,
if i got you right, you want to write data from session into another. The gap there is you will have to know the session-id from each session. if you know them, you can accomplish the task with the following code: <?php // SESSION-ID of the session to write in is in $newSessId; // Save data from current Session session_write_close(); $oldSessId= session_id($newSessId); // Change to new Session session_start(); // Delete/Alter data into Session unset($_SESSION['unsetvar']); $_SESSION['altervar']="newvalue"; // Save changes into Session session_write_close(); // Switch back to previous session session_id($oldSessId); session_start(); ?> best regards deniz adrian Ikke wrote: > I have to share a variable between browser sessions. > One session for example changes the variable, the other sessions must > see the changes (get the new value instead of the original value) > it's not allowed to save the value in a database or to save it into a > file. It must be a kind of global server variable, changeable by every > session. > > tia |
|
|||
|
What about cookies?
"Ikke" <ikke_mmv@hotmail.com> ???????/???????? ? ???????? ?????????: news:42127f06$0$12085$a344fe98@news.wanadoo.nl... >I have to share a variable between browser sessions. > One session for example changes the variable, the other sessions must see > the changes (get the new value instead of the original value) > it's not allowed to save the value in a database or to save it into a > file. It must be a kind of global server variable, changeable by every > session. > > tia -- Happy PHP'ing,(c) Team Zend |
|
|||
|
thanks for your inputs.
I've solved it with shared memory. shmop (http://www.php.net/manual/en/ref.shmop.php) greetings |