For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2005 > How to share a variable between browser sessions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to share a variable between browser sessions
Ikke

2005-02-15, 8:56 pm

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

2005-02-15, 8:56 pm

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


Chris Hope

2005-02-15, 8:56 pm

tintub@gmail.com wrote:

> Ikke wrote:

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.
[color=darkred]
> 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/
Deniz Adrian

2005-02-16, 8:57 am

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

Yevgen Varavva

2005-02-16, 8:57 am

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


Ikke

2005-02-16, 3:57 pm

thanks for your inputs.
I've solved it with shared memory.
shmop (http://www.php.net/manual/en/ref.shmop.php)

greetings
Ikke

2005-02-21, 3:57 pm

thanks for your inputs.
I've solved it with shared memory.
shmop (http://www.php.net/manual/en/ref.shmop.php)

greetings
Yevgen Varavva

2005-02-21, 3:57 pm

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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com