Issues with database connections, it is being cached in Chrome/IE browsers

I have deployed my application in production environment twice, one is intended to be used by users as LIVE and other as a VALIDATION environment in same physical server.

  • The database connection were created to point to different servers as follow:
    LIVE deployment was pointed to server DB1 (containing production data)
    VALIDATION deployment was pointed to server DB2 (containing test data)

The problem is as follow:

When I run the LIVE application obviously it display data from DB1 which is fine, but if I open VALIDATION in a separate browser tab/window the shown data is still for DB1, but it should show data from DB2. To temporally fix that I have to clear browser cache (cockies, temp files, etc). If after clear cache I open VALIDATION again it will display data from DB2 which is fine, but if open LIVE in other tab/window it will display data from DB2 also.

I have tried with Chrome and IE with same results.

Seems like both applications are taking database connection from some cached data.

Your help will be very appreciated.
Thanks!

It is not cache that is causing the problem.

The problem that you are seeing is due to the fact that the session data is being shared by all instances of a particular browser running on a pc. You will notice if you run IE and Chrome at the same time, they will not conflict with each other, since the session data is not being shared.

That said, it is important to note that the session data lives on the SERVER, not in the browser. The particular set of session data to be used on the server is identified by a cookie that does live in the browser, but essentially since cookies are shared among all of the tabs (or windows for that matter) of a browser instance, it can’t be solved by simply creating a new cookie.

Each page access in a browser window is an independent event. Session data is sort of a way to change the stateless nature of a browser connection to a stateful one. Unfortuanately, the server has no idea that you have two tabs open, or which one you clicked a button in.

But none of this really helps your situation.

What you need to do:

In the root directory of your VALIDATION project, create/edit a file called .htaccess and put in the following line:

php_value session.name “VALSESS”

VALSESS can be any string you would like, except the normal default of PHPSESSID. This will use a different cookie name to store the Session ID in your browser for the validation website. Should make everything work the way you want.

Dave

1 Like

As an afterthought, you can probably open the second tab as an “anonymous” browser window (in FireFox it is called a “Private Window”).

The new window does not know any cookies so it should not use the same Session Data on the server.

I have not tried this, but in theory it ought to work.

Dave

1 Like

Dave, now saw this post of yours, from what I understand, my English is not at its best, you say that you modify the .htaccess file and place the following value:

session.name php_value “VALSESS”

I place so as such as this? This would make the sessions are independent cookies?

I appreciate your help and your time. Greetings.

Leandro,

Yes, but you need to do that for each different production environment.

For example, say you have one project in scriptcase, and you are deploying it to two different websites, i.e. www.myproject.com/production and www.myproject.com/testing, then you can use this method to have the session variables not interfere with each other if you open the two sites in different tabs of your browser. the “VALSESS” needs to be different for the two websites, maybe using something like “TESTSESS” and “PRODSESS”.

Another approach would be to name the sites differently. For example test.myproject.com and prod.myproject.com will always use different sessions because the root of the URL is different.

Dave