views:

33

answers:

2

I have a PHP and HTML based CMS. In each page of the CMS, there is a form with a Javascript-based tabbed dialog that switches between a number of DIVs.

From each page of the CMS, it is possible to open a preview page to see the changes made, and then return to the CMS. When the user returns, I would like the same tab page to be opened as when they left for the preview.

My current approach is to change the value of a cookie ("current_tab") each time the user changes a tab.

onclick='setCookie("current_tab", 5);'

When the tabbed dialog is generated, I check for the cookie and set the appropriate DIV to "display: block".

However, I need the cookie setting to be limited to that specific CMS page, and not all of them. If the user changes to a different page, the tab must not be pre-selected.

My current approach is to create a cookie for each page, e.g. for page ID 10254:

onclick='setCookie("current_tab_10254", 5);'

and, as an attempt of cleaning up, to remove that cookie when the page is rendered. But obviousy, this is not going to clean up every cookie that was set, because the user can choose not to return to the form, or navigate to a different page. I fear clutter through dozens of cookies in the system.

Does anybody have a better idea how to do this?

+1  A: 

Try to Limit visibility of cookies by changing "path" parameter of cookie.

If structure of your application doesn't allow this, I'd suggest you not to use such approach, cause cookies are usually sent with every request, including requests to static information (images, css).

Dienow
Mmmmm interesting idea but don't think it solves the cluttering problem, does it? I might be able to change the CMS's path structure accordingly, but on the long run, a lot of cookies (one for each page) would amass in the user's browser - only that they are all named the same and have different base paths?
Pekka
Oh, common I don't think that this would influence user's experience =)I also have following crazy idea: you can store your settings in database. When user switches tab you store this to cookies, but next time he makes ANY query to your application, you remove all data from cookies that is related to tabs positions and store it to database. The only disadvantage I see is that it is too complicated logic for such simply task.
Dienow
+1  A: 

Why are you worried about removing the cookies? They will expire and remove themselves.

Justin Johnson