PHP Session Sharing
Moderator: General Moderators
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
PHP Session Sharing
Hi all
I have a very basic question. what is the range on PHP session variables? if I open the same PHP page on the same computer in different browsers, they share the same session. Is there a way to make different browser share different sessions??
I have a very basic question. what is the range on PHP session variables? if I open the same PHP page on the same computer in different browsers, they share the same session. Is there a way to make different browser share different sessions??
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP Session Sharing
I may be wrong, but I'm pretty sure sessions are browser specific. Each browser keeps track of it's own cookies, and the session ID is usually stored in a cookie. Are you sure they shared the same session?
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP Session Sharing
that s something I used to believe... but I tested it in two browsers going to the same page. if I change session variable in one page and refresh the other, the other changes the output.
I found if I close all the IE window the session will be killed, but lets say I have window A, B, C open and A and B pointing to my test page while C point to some random page. If I just close A and B and open up window D to go to my test page, my session still exist.
Can this be some setting in PHP.ini?? it seems like everytime I have an problem it's always some setting in that file....
I found if I close all the IE window the session will be killed, but lets say I have window A, B, C open and A and B pointing to my test page while C point to some random page. If I just close A and B and open up window D to go to my test page, my session still exist.
Can this be some setting in PHP.ini?? it seems like everytime I have an problem it's always some setting in that file....
Re: PHP Session Sharing
Different browsers have different sessions. That is a fact. They store it at completely different physical locations. Unless you are using a custom installation of multiple IE or something like that.
Please show us your code.
Please show us your code.
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP Session Sharing
ok here is an example code I used.
If I open two browser, on the first one goto "index.php?var=a" . It display "a". On the second one I just go to "index.php" , it also display "a".
Code: Select all
<?php
session_start();
if(isset($_GET['var'])){
$_SESSION['var'] = $_GET['var'];
}
echo $_SESSION['var'];
?>
Re: PHP Session Sharing
The code you use sets the session variable whenever the $_GET variable exists. Since you use the same URL in all browsers - you get the same results (as the URL contains the same $_GET variable)
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP Session Sharing
no pytrin, the second browser I used index.php without any query attatching to it, so it shouldn't detect there is any $_GET variable.pytrin wrote:The code you use sets the session variable whenever the $_GET variable exists. Since you use the same URL in all browsers - you get the same results (as the URL contains the same $_GET variable)
Re: PHP Session Sharing
Try clearing the cookies in both browsers and try again - you might have done it by accident before and now it remembers the state. What browsers are those by the way?
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP Session Sharing
I cleared the cookie and it still perform the same =( I am using IE 8 ....
Re: PHP Session Sharing
Different windows of the same browser will use the same cookies. That means the same session.
Different browsers will use different cookies. That means different sessions.
Different browsers will use different cookies. That means different sessions.
Re: PHP Session Sharing
Are you using the same browser ... ?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP Session Sharing
If you're just using multiple windows of the same browser, there is no way I know of to prevent them sharing that session across windows. Why would you want to prevent that?