0

For this code:

page1.cfm
<form action="page2.cfm" method="post">
<input type="text" name="name" />
<input type="submit" />
</form>

page2.cfm
<cfset session.name = form.name>
<cflocation url="page3.cfm" addtoken="no">

page3.cfm
<cfdump var="#session.name#">

If you do this:

  • browse to page1.cfm on any browswer
  • submit the form with "value1"
  • open a new tab
  • browse to page1.cfm and submit the form with "value2"
  • go back to the first tab and refresh the page

You will notice that the value of session.name changes on the first tab.

In this question, one of the answers is followed by the comment, "If tabbed browsing causes issue with your session variables, you are doing it wrong".

How then, do you do it properly? The objective is to preserve "value1" on the first tab and "value2" on the second.

Community
  • 1
  • 1
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
  • 1
    I would say that in this use case, you are using session variables incorrectly. And that the session scope, is working as designed. Neither ColdFusion, nor any web application server, I believe, will treat 2 different tabs opened in the same browser window as 2 different 'sessions'. This is not a problem unique to ColdFusion. – Scott Stroz Aug 12 '14 at 00:33

1 Answers1

3

Hopefully Scott will post his own comment/answer here but I suspect you misinterpreted his comment. What you describe here is exactly how browsing has always worked for me. Before "tabbed" browsing existed this same issue arose when you opened a new browser window without closing the existing one (this happens no matter how many browser windows you open and still happens today). The ColdFusion server will only maintain a single session for every browser instance the user has open. Hence the warning that all of us display when a user logs out of a session based application. Something along the lines of "your session will not be completely closed until you exit all of your browser windows". Or when they log in "you already have an active session, your other session will be terminated". Then came tabbed browsing. Well tabs are nothing more than another browser instance, just like before, only contained within the same window.

So tabbed browsing does not cause an issue with session variables, they are working as designed. This is how it works. This is expected behavior. It is your expectation that is wrong. I am sure there are ways to make it work the way you are expecting, like there always is in programming, but that is going against the way browsers are designed. Is that a direction you really want to go?

Duplicate question - How to differ sessions in browser-tabs?. You will see some examples there but they are all hacks in an attempt to make it work differently than designed.

Community
  • 1
  • 1
Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • While Scott was the person who made the comment in the question to which I referred, he is not the only person who has said words to that effect. – Dan Bracuk Aug 11 '14 at 18:43
  • 1
    I think you are missing the point I was trying to make. They are correct - tabbed browsing does not cause issues with session variables. The issue is that you believe different session values should be maintained between different tabs for the same session. That's wrong. – Miguel-F Aug 11 '14 at 19:04
  • 1
    @Miguel-F - You did a much better job at making my point than I did, thank you for that. What I should have said was - if you expect tabs in the same browser to maintain different sessions, you are doing it wrong - or more to the point, your expectations are wrong. – Scott Stroz Aug 12 '14 at 00:29