473,226 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 8436
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.