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        1
I 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.