admiral_grinder has asked for the wisdom of the Perl Monks concerning the following question:

My app uses HTML cookies deposited by both perl and javascript. Perl for the beef and JS for the UI. The problem is that when a user logs off I want to remove all the cookies so that all of the UI settings are reset for the next user. For example, selecting a item after browsing through a tree. The JS cookie keeps track of what is open in the tree so they can revisit it later easily. When the current user logs off, then the next user can then see where the one before has been. Assuming that the browser isn't closed between users.

I understand how to manipulate the cookies in the Perl, but I can not modify the cookies that the JS put in. I can view them and get data from them just fine, but I can't change their stats as to force them to expire. Perl cookies, no problems there, just the JS ones. Any help will be appreciated.

  • Comment on PERL Cookies playing with JavaScript Cookies

Replies are listed 'Best First'.
Re: PERL Cookies playing with JavaScript Cookies
by shiza (Hermit) on Aug 04, 2005 at 18:28 UTC
    The method used to set the cookie should be independent of the cookie itself. Are you restricting access to a specific path? If so, maybe the Perl script isn't allowed to access it because it isn't in the required path.
      I'm not quite folllowing you about the path part because in the perl I do a CGI::Application->cookie() and I get all the cookie names that I want to change. Both Perl and JS. I can use the values from both too, I can't modify the JS ones though.
        The default path for CGI.pm cookie is '/'. If your JS is creating the cookie in another path Perl probably will not read it. You can see the cookie's path in your browser (at least I can on Firefox).


        Igor S. Lopes - izut
        surrender to perl. your code, your rules.
Re: PERL Cookies playing with JavaScript Cookies
by injunjoel (Priest) on Aug 04, 2005 at 20:14 UTC
    Greetings all,
    Maybe I don't fully understand the issue but I would think that on each login by a user you could clobber the previous JS cookie by resetting it.
    To get around the issue of a previous user wanting to revisit where they were on their last login you would need to store the contents of their cookie in a db || text file associated with their account information.
    So the flow would be something like:
    • User logs in.
    • The system authenticates their username and password and selects out their last-visited postion in the tree.
    • The JS cookie is set with the last-visited information by writing the JS code from within Perl to populate the correct value.
    • User browses around updating the JS cookie for their last-visited location.
    • Upon loggin out you would need to write some JS code to post to a Perl script that will store the value of the JS last-visited cookie. This could be accomplished by using a hidden field to pass the last-visited value to your logout script and deal with it there.
    Are you absolutely sold on using JS for your cookies? I would think using Perl for all the cookies would be a bit easier to maintain. Or is the entire Tree rendered in DHTML? so there are no subsequent server requests that go out while browsing?

    -InjunJoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
      Hi. I am using Perl/JS/HTML for a multi-user project also requiring login/passwd authentication, and I have a similar problem. I write my cookies in Perl manually, and a small hand-written parser to evaluate them. I know there is no extra code going in there, but cookies written in JS are not over-written by my Perl cookies. In fact, I get TWO cookies, lexically identical keys, with different values. Somehow the browser knows which is which. Same problem on IE and Opera. Not sure about FF.
Re: PERL Cookies playing with JavaScript Cookies
by Transient (Hermit) on Aug 04, 2005 at 18:02 UTC
      I don't know if I'd trust a page that is supposed to be a Javascript resource, when it itself contains erroneous Javascript:
      Error: unterminated character class Source File: http://msdn.microsoft.com/workshop/code/browdata.js Line: 26, Column: 31 Source Code: else if (this.userAgent.match(/Mozilla[/].*(95[/]NT|95|NT|98|3.1). +*Opera.*(\d+)\.(\d+)/))
      ;^D
      That looks like some JS methods to handling cookies. We got the JS dropping the cookies fine, it is that we want to use Perl to manipulate them once in a while.