martell has asked for the wisdom of the Perl Monks concerning the following question:
After tearing my hear out for more then 3 hours, i thought i share this little thing for novices who try to develop a website with cookies in perl. Battered monks will know this, but it isn't documented anywhere in the documentation around the apache2::cookie module
The thing is, novices start to program from a local machine. And just on this local machine, setting cookies is tricky. The browser seems not to get the cookie in some way.
I finally found the clue somewhere deep down the apache and php documentation. When you sending a cookie from a localhost the domain you should use is a blanc space aka " ". This allow the browser to accept the cookie from the local machine
Sending a cookie with apache2::cookie from a website on localhost, becomes:
use Apache2::Cookie; # make a cookie Apache2::Cookie->new ( $r, -name => 'my_name', -value => 'test', -path => '/', -domain => ' ', #this is the clue... -expires => '+15m', )->bake($r);For using MasonX::Request::WithApacheSession, the same problem appears. You should be using something like following settings in your httpd.conf
PerlSetVar MasonArgsMethod mod_perl PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession PerlSetVar MasonSessionCookieDomain " " PerlSetVar MasonSessionClass Apache::Session::File PerlSetVar MasonSessionDirectory /tmp/www/sessions/data PerlSetVar MasonSessionLockDirectory /tmp/www/sessions/locks PerlSetVar MasonSessionUseCookie 1I hope this helps novices like me in the futer. Any additional thoughts and remarks are appriciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending Cookies from localhost with perl
by rowdog (Curate) on Apr 03, 2010 at 20:02 UTC | |
by martell (Hermit) on May 17, 2010 at 19:12 UTC | |
by rowdog (Curate) on May 18, 2010 at 14:16 UTC | |
by martell (Hermit) on May 19, 2010 at 21:27 UTC | |
|
Re: Sending Cookies from localhost with perl
by Anonymous Monk on Apr 02, 2010 at 23:28 UTC |