473,473 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
5 8484
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


Jul 17 '05 #2
ti****@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/
Jul 17 '05 #3
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

Jul 17 '05 #4
What about cookies?

"Ikke" <ik******@hotmail.com> ???????/???????? ? ???????? ?????????:
news:42***********************@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
Jul 17 '05 #5
thanks for your inputs.
I've solved it with shared memory.
shmop (http://www.php.net/manual/en/ref.shmop.php)

greetings
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom | last post by:
Hi, I would like to use the standard PHP sessions and I understand they rely on the target web browser to support session cookies. I have tried the following code: <? session_start(); if...
3
by: Daniel | last post by:
right now i have some sql server tables that i search for a value w/ a key each time a .aspx is hit. is there any way i can just have the first hit to the .aspx select all the entries from the...
11
by: Sara T. | last post by:
All, How can I share variable between web site ? I mean that I have two web sites but I need to use the same variable, how can I do ? I try to use session or application but it doesn't work. ...
2
by: Wayne Wengert | last post by:
Are Session variables the same as a cookie? In reading a couple of pages I got from searches, I don't get the difference. Basically, I am currently using simple session variables (e.g....
7
by: mateus | last post by:
print "hello world" I have a nested loop where the outer loop iterates over key value pairs of a dictionary and the inner loop iterates over a list each list of which is a mapped value from the...
1
by: dotnetmuddu | last post by:
Hi, Have you guys come across this ? Can I share the session state between virtual directories. Ex : I have Virtual Dir SessionTest1 & SessionTest2. If a variable Session = "testuser"...
6
by: laredotornado | last post by:
Hi, When a user logs into our site, we create a session variable to denote the session is active and another to denote who is logged in. Once the user closes the browser and re-opens it, the...
8
by: YYZ | last post by:
I'm using asp, not asp.net. I've got some open ended questions that I was really hoping someone in here could answer, or direct me to some resources that will help me answer them on my own. ...
6
by: Immortal Nephi | last post by:
First class is the base class. It has two data: m_Base1 and m_Base2. Second class and third class are derived classes and they are derived from first class. m_Base1 and m_Base2 are inherited into...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.