473,581 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling multiple sessions??

How do u guys handle multiple sessions??
i.e, opening different browser windows by running
iexplore.exe or clicking IE icons and opening the application. My
sessions are mixing up.
what i mean is
suppose i log in my site using username "test".
At this time I set $_SESSION['name']="test".
And I use $_SESSION['name'] inside my application to print the
username.
Now if I open another browser & log in with "another test" the session
variable is overwritten.Ano ther session is not created.

Do you store the session in database or pass the session_id via get or
post.
Jul 17 '05 #1
4 31177
"john" wrote:
How do u guys handle multiple sessions??
i.e, opening different browser windows by running
iexplore.exe or clicking IE icons and opening the application. My
sessions are mixing up.
what i mean is
suppose i log in my site using username "test".
At this time I set $_SESSION[’name’]="test".
And I use $_SESSION[’name’] inside my application to print
the
username.
Now if I open another browser & log in with "another test" the session variable is overwritten.Ano ther session is not created.

Do you store the session in database or pass the session_id via get or post.


John, that is by design. You cannot have multiple users logged in
with the same session variable. When you open another browser, it
should not allow login, but say "user is logged in", and allow
logout. Once the user logs out, then the login boxes appear.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-handling...ict139652.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467184
Jul 17 '05 #2
ma************* *****@yahoo.com (john) wrote in message news:<4c******* *************** ****@posting.go ogle.com>...
How do u guys handle multiple sessions??
i.e, opening different browser windows by running
iexplore.exe or clicking IE icons and opening the application. My
sessions are mixing up.
what i mean is
suppose i log in my site using username "test".
At this time I set $_SESSION['name']="test".
And I use $_SESSION['name'] inside my application to print the
username.
Now if I open another browser & log in with "another test" the session
variable is overwritten.Ano ther session is not created.

Do you store the session in database or pass the session_id via get or
post.


IMO, this question has been asked so many times. You should have
searched the archives
<http://groups.google.c om/groups?threadm= abc4d8b8.031218 0003.4df5d9f5%4 0posting.google .com>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3
R. Rajesh Jeba Anbiah wrote:
ma************* *****@yahoo.com (john) wrote in message news:<4c******* *************** ****@posting.go ogle.com>...
How do u guys handle multiple sessions??
i.e, opening different browser windows by running
iexplore.ex e or clicking IE icons and opening the application. My
sessions are mixing up.
what i mean is
suppose i log in my site using username "test".
At this time I set $_SESSION['name']="test".
And I use $_SESSION['name'] inside my application to print the
username.
Now if I open another browser & log in with "another test" the session
variable is overwritten.Ano ther session is not created.

Do you store the session in database or pass the session_id via get or
post.

It's all well and good to say the question has been asked lots, but it
would be more useful to provide a link to an instance where it has been
answered. When you can't put your finger on the problem (and associated
jargon), it's very difficult to find something in google using general
searches. Because you understand the problem, you take it for granted
that it is easy to find the solution. Not so if you don't understand the
problem. I wish people wouldn't tell other newbies to go Google when
they are genuinely in need of help and are not just being lazy.
For all the reasons you (original poster) mentioned, any web application
is infact a multi-threaded (each page/script request is a thread)
application which has to deal with the issue of "concurrenc y". This is
not an issue of the technology (in this case, PHP) as much as code
design. You have to design your application in such a way as to deal
with multiple operations happening at unpredictable times in
unpredictable order. PHP session management allows you to centralise
where persistant name/value pairs are stored, but it doesn't solve your
concurrency issues. These issues are broader than any given
language/platform and are widely discussed in many programming forums.
The issue generally revolves around [multi-channel, asynchronous] access
to a central data store. This could be anything from session vars, to a
file on the server, or to a database.

Search google for issues relating to "programmin g for concurrency"
topics in general. Once you get the concept, then common sense prevails.
You begin to understand why using functions like flock() are relatively
beneficial (be it somewhat flawed given the possible http service model
of your web server).

The fact that the issue actually occured to you is a good sign. I don't
think you will have too many difficulties understanding the problem and
how to deal with it. Many so-called web "developers " never even twig to
race conditions and concurrency. Then they wonder why the get
"unexpected " behaviour and/or corrupt data.

I found an article which mentions that it is good to use the same
database connection resource but that's all I could find that was PHP
specific. Apparently, it is not all that easy to turn up really good
articles in Google. This is all I could come up with in reasonable time.
http://www.devshed.com/index2.php?op...ge=0&hide_js=1
Maybe there is a good reason why people have to keep asking this
question on forums ;) If you have more questions in your quest on this
topic, don't be put off by people telling you to go google. Ask away.
"There is no question `stupider' than the one everyone had but was too
afraid to ask".

Jul 17 '05 #4
Having different sessions with multiple browser instances can be done, but
it requires some less-than-simple effort. To have a different session you
must use a different session id.

Option (a) - you can bypass cookies and pass the session id within every
URL, but this presents a security risk as that session id is clearly visible
to the outside world and can be hijacked.

Option (b) - if you are using cookies (the preferred option) then the
session id is linked with a session name, the default being PHPSESSID. The
solution that I have found is to use a different session name for each
session. This allows the single cookie maintained by the web browser to
contain multiple session id's, each with their own session name.

Step 1 is to override PHP's default session name. I use a .htaccess file
with the following entry:

php_value session.name fred

Step 2 is to include a hidden field called "session_na me" in every screen.

Step 3 is to execute the following code at the start of every script:

global $session_name;
if (isset($_REQUES T['session_name'])) {
// use session name passed via $_GET or $_POST
$session_name = $_REQUEST['session_name'];
} // if

Step 4 is to have the following code in your logon script:

// get details from any previous session
if (isset($session _name)) {
// use existing session name
} else {
// assign new session name
$session_name = getNewSession(' menu');
} // if
session_name($s ession_name);
session_start() ;
session_unset() ;
initSession();

This uses the following user-defined functions:

function getNewSession ($prefix='fred' )
// create a new session name using $prefix + a 1 digit number
{
// step through numbers 0-99
for ($i = 0; $i <= 99; $i++) {
$session_name = $prefix .$i;
if (!array_key_exi sts($session_na me, $_COOKIE)) {
break;
} // if
} // if
return $session_name;
} // getNewSession

function initSession()
// standard session initialisation
{
....
if (!isset($_SESSI ON)) {
if (isset($session _name)) {
session_name($s ession_name); // set the session name
} // if
session_start() ; // open/reopen session
} // if
....
} // initSession

Note that this will allow a suffix of 0-99 on the end of the session name of
"fred".

Step 5 is to have the following code at the start of every script
(immediately after the code identified in step 2):

initSession();

This has the following effect:

The URL for the logon screen does not contain the parameter "session_na me",
therefore the logon screen will always generate a new session name.

The URL for every other screen will contain "session_na me", therefore it
will continue to use the session with that name and the session id
associated with that name.

If within a browser window the user creates a copy of that browser window
then the existing session name will also be copied, in which case the same
session will be used by more than one browser instance. This can be remedied
by pressing the "logout" URL which will invoke the login screen which in
turn will generate a new session name and hence a new session id.

As you can see it is not trivial, but it can be done.

--
Tony Marston

http://www.tonymarston.net
"R. Rajesh Jeba Anbiah" <ng**********@r ediffmail.com> wrote in message
news:ab******** *************** ***@posting.goo gle.com...
ma************* *****@yahoo.com (john) wrote in message
news:<4c******* *************** ****@posting.go ogle.com>...
How do u guys handle multiple sessions??
i.e, opening different browser windows by running
iexplore.exe or clicking IE icons and opening the application. My
sessions are mixing up.
what i mean is
suppose i log in my site using username "test".
At this time I set $_SESSION['name']="test".
And I use $_SESSION['name'] inside my application to print the
username.
Now if I open another browser & log in with "another test" the session
variable is overwritten.Ano ther session is not created.

Do you store the session in database or pass the session_id via get or
post.


IMO, this question has been asked so many times. You should have
searched the archives
<http://groups.google.c om/groups?threadm= abc4d8b8.031218 0003.4df5d9f5%4 0posting.google .com>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com

Jul 17 '05 #5

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

Similar topics

13
12032
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location on the server (in our own accounts on the same machine). When I am testing both versions of our program using the same browser (IE on Windows or...
1
1913
by: niyaz | last post by:
Is it possible to use 2 or more sessions at the same time on the same page? thanks for any help, Niyaz
4
2781
by: Goalie | last post by:
Dear all, I have a script which checks whether a user is logged in and on which level. If he is not logged in, he will get the login screen. My problem is that the script works on the server of the ISP, but not on my local machine. I checked me php.ini files and also phpinfo on the ISP server. But what happens is that if I try to log in on...
1
3487
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The web.config file is configured as such: <authentication mode="Forms"> <forms loginUrl="Login.aspx" protection="All" name="myApplication"/>...
2
1619
by: Don | last post by:
I'm asking this for a friend of mine, so forgive me if I'm getting some of the terminology wrong (I don't have any experience with ASP.NET). I've got an ASP application that has some classes that have shared members. How do I set it up so that each individual session uses a different "copy" of each shared class? Right now, every session...
4
2331
by: Shankar Reddy | last post by:
Hi All, Problem: Data is being shared across multiple sessions in ASP.NET! Does anybody come across this kind of situation where session data or view state data is being shared across different sessions? is it a bug in ASP.NET? or is it some thing i have to take care programatically when we develop asp.net application?
0
1278
by: YVT1968 | last post by:
Hi, Here is the problem statement. I have an asp.net application, let's call it "A". From this application, I open 3 more applications, let's call them, A1, A2, A3. Now, in the default page on A, I have a logout button. On clicking of this logout button, I want to clear session for A1, A2 and A3. The three applications have three different...
3
2198
by: Mangler | last post by:
I have 2 sessions that get created. One when the user logs in called "uname" and another called "idrma" when that user choses to begin a repair request. I know <%session.abandon% will kill both sessions, how to I only target one?
1
1658
by: Bluejay906 | last post by:
This is another one of the endless oddities about this Access application that I have inherited. This one has me stumped. The users found that if they have two sessions of the application running, both on forms that have a data backend (i.e. that is getting data from a table or a query), the forms update faster than if they have only one session...
0
7868
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8175
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5674
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5364
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
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 we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.