Page 1 of 1
PHP Session Sharing
Posted: Thu Oct 07, 2010 6:30 pm
by williamshen25
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??
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 6:38 pm
by Jonah Bron
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?
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 6:50 pm
by williamshen25
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....
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 7:14 pm
by Eran
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.
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 7:34 pm
by williamshen25
ok here is an example code I used.
Code: Select all
<?php
session_start();
if(isset($_GET['var'])){
$_SESSION['var'] = $_GET['var'];
}
echo $_SESSION['var'];
?>
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".
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 7:48 pm
by Eran
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
Posted: Thu Oct 07, 2010 7:51 pm
by williamshen25
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)
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.
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 7:55 pm
by Eran
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?
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 7:59 pm
by williamshen25
I cleared the cookie and it still perform the same =( I am using IE 8 ....
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 8:24 pm
by requinix
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.
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 8:30 pm
by Eran
Are you using the same browser ... ?
Re: PHP Session Sharing
Posted: Thu Oct 07, 2010 11:51 pm
by Jonah Bron
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?