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
In reply to Sending Cookies from localhost with perl by martell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |