How to share a variable between browser sessions

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2005
Ikke
 
Posts: n/a
Default How to share a variable between browser sessions

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
Reply With Quote
  #2 (permalink)  
Old 02-16-2005
tintub@gmail.com
 
Posts: n/a
Default Re: How to share a variable between browser sessions

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


Reply With Quote
  #3 (permalink)  
Old 02-16-2005
Chris Hope
 
Posts: n/a
Default Re: How to share a variable between browser sessions

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/
Reply With Quote
  #4 (permalink)  
Old 02-16-2005
Deniz Adrian
 
Posts: n/a
Default Re: How to share a variable between browser sessions

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

Reply With Quote
  #5 (permalink)  
Old 02-16-2005
Yevgen Varavva
 
Posts: n/a
Default Re: How to share a variable between browser sessions

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


Reply With Quote
  #6 (permalink)  
Old 02-16-2005
Ikke
 
Posts: n/a
Default Re: How to share a variable between browser sessions

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

greetings
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0