Perl + web cookies, not sure why this is failingby desertrat (Acolyte)
|on Mar 03, 2012 at 17:30 UTC||Need Help??|
desertrat has asked for the
wisdom of the Perl Monks concerning the following question:
I'm working on a web app that requires a certain cookie to be set, and it seems like setting the cookie is taking place AFTER the web script checks for it. The first time the web page is loaded (and this has been tested in three different web browsers) the script cannot find the cookie, even though if you look (for instance, in Web Inspector in Chrome) the cookie is clearly set.
If you reload the page, then the cookie is found, of course, but Im setting the cookie before I ever send anything to the browser, so why isn't it found immediately? At first I tried putting the check and setting of the cookie in a perl module that's called by all of the scripts involved, but that didn't work. Thinking that this had something to do with mod_perl, and the module only being compiled once, I made it a sub in the module and call the sub in the script itself.
That produces the same result. Running it on a non-mod-perl apache instance also produces the same result. I"ve got a demo code that will do this, a .pm file and .pl file that's actually run as the cgi script.
A test page is here
It will display the returned result from running the cookie-setting sub, then display the result of the check.
Here's the code :
And the actual script: