[Dancer-users] Managing "sessions" for each open browser window

Assaf Gordon gordon at cshl.edu
Mon Sep 24 19:48:39 CEST 2012


Hello,

Another implementation question for my planned web-site:

I want to maintain a "session" (i.e. collection of server-side variables) for each open browser window (not browser "session" in the technical sense).

Use-case:
1. a user open a new browser window/tab, goes to my web-site.
2. user changes settings, does some stuff, information is stored for this "session" of open window.

3. same user, same browser, opens a new window/tab, goes (again) to my web-site - now gets a new "empty" session.
4. user changes settings, does some stuff, information is stored for this "session" of open window.

5. the two browser windows (from step 2,4) can be viewed side-by-side, each maintaining independent set of session information.


Implementation-wise, I've seen similar web-sites assign a new CGI variable when a user visits the "root" (=landing) page, and propagate that variable in every generated link or HTML form.
e.g.:
1. user visits http://myserver.com
2. user redirected to http://myserver.com/?session_id=5
3. from now on, every URL (generated by Dancer's templates) will carry the session ID.
4. if the user opens a new (empty) tab and visists "http://myserver.com" again, he will get "session_id=6" for that window.

This seems reasonably easy to implement, but how do I connect the CGI session variable to some sort of Dancer's "session" keyword?
I'm thinking of some "before" hook mechanism, but not sure how to go about it...

Any suggestions are welcomed,
 -gordon

P.S,
I'm aware that a mischievous user could copy&paste the URL to another window, and have two open windows changing the same "session" - I'm not worried by this scenario (as users will be explained that such a thing will simply interfere with their work).


More information about the Dancer-users mailing list