0

I have a problem here. I tried to login into one account. Then opening another chrome session not another tab the previous session gets this session value and everything reset to current account value. How avoid this problem? This is how I do in my login page. MY server is Centos.

            $_SESSION['enterpriseID'] = $row1['enterpriseID'];
        $_SESSION['userID'] = $row1['userID'];
        $_SESSION['userName'] = $row1['userName'];
        $_SESSION['enterpriseName'] = $row1['enterpriseName'];
        $_SESSION['enterpriseID'] = $row1['enterpriseID'];
        $_SESSION['enterpriseLogo'] = $row1['enterpriseLogo'];
        $_SESSION['timeZoneOffset'] = $row1['timeZoneOffset'];
        $_SESSION['positionID'] = $row1['positionID'];

Sample code is as below.

Update tblAST Set 
astStatus='m',".
employeeIDEnd=".$_SESSION['userID'].", ".
dateTimeEnd=now() ".
Where astID=".$astID;
user2711681
  • 285
  • 7
  • 16

1 Answers1

2

The way that chrome works is that the sessions are valid through out the program, even if you open a new window it still has the information from all the other sessions. you can see this by using GMail, every window that you open up your inbox will load while you go to it,

as mentioned above, try using private browsing or a different browser to test the multiple sessions.

As mentioned in my comments below you need to assign a name to each session then make a multi dim array to set and retrieve the information.

$_SESSION['myapp']['username']
$_SESSION['myapp']['id']

Philip
  • 55
  • 1
  • 8
  • The problem is that I tried on IE is the same too. I also saw some data getting session id of different customer when stored in the database that is scary – user2711681 Sep 17 '13 at 15:32
  • Because all browsers use a global session, and the variable gets written over. try using private mode, or even database sessions this way you can generate a key for each session, i beleive php has a way for doing that, where you reference session by keys – Philip Sep 17 '13 at 15:34
  • But why is my db also showing mixed up of the customer session value. For eg. I see the customer A having the session value of customer B being stored – user2711681 Sep 17 '13 at 15:34
  • i did a quick search look at this post http://stackoverflow.com/questions/854105/multiple-php-sessions – Philip Sep 17 '13 at 15:36
  • Every page I have this session_start(); – user2711681 Sep 17 '13 at 15:38
  • once you start the session you need to get the session from the user that is logged in. this way you can get it by key for the session that you want to write in – Philip Sep 17 '13 at 15:48
  • yes I do that by first putting session_start(); at the very top of every codes – user2711681 Sep 17 '13 at 15:51
  • yes you put that to start the session, that is correct but then you need to actually get the session identifier for the user, please have a look at http://php.net/manual/en/function.session-name.php – Philip Sep 17 '13 at 17:36
  • This how I get the values $_SESSION['userID'] ? – user2711681 Sep 17 '13 at 17:40
  • when you set the values you need to access that variable $_SESSION['myapp']['username'] $_SESSION['myapp']['id'] – Philip Sep 17 '13 at 17:49
  • @How to set then as I only know one method to set the session? – user2711681 Sep 18 '13 at 17:14
  • Look at this thread http://stackoverflow.com/questions/854105/multiple-php-sessions – Philip Sep 19 '13 at 20:03