Monks, I'm banging my head against the wall here. I just can't seem to set a cookie.

I'm using the following set up.

Apache/2.0.54 (Win32) mod_perl/2.0.1 Perl/v5.8.7
Within the httpd conf I've defined the following, to pick up any dynamic requests...
<Files ~ ".*"> SetHandler perl-script PerlHandler MyOrg::Apache::User PerlSendHeader On Options ExecCGI </Files>
I've got my own handler here because I'm picking up the the uri, and using it to run template toolkit against an appropriate file. This goes something like this (a bit cut down)...
sub handler { my $r = shift; # use the path_info to determine which template file to process my $file = $r->unparsed_uri; # validate the url as a content page my $tt_path = $nav->get_path_attribute("/$file", 'local_path'); $tt_path =~ s[^/][]; return -1 if ! $tt_path; # Decline this request if the path isn't +in the nav # set up and call the template my $template = Template->new({ PLUGIN_BASE => 'MyOrg::Template::Plugin', INCLUDE_PATH => "$websrc:$websrc\\lib", PRE_PROCESS => 'config', OUTPUT => $r, # direct output to Apache request }); my $params = { uri => $r->uri, navigation => $nav, }; $r->content_type('text/html'); $r->headers_out->add('Set-Cookie' => "CGISESSID=PLEASEWORK; path=/ +"); $template->process($tt_path, $params) || return fail($r, 500, $template->error()); ## 500 -> SERVER_ +ERROR return 0; # OK }
... with $nav being a pre-created object which looks after which uri's compile which templates (although, all this works nicely, so only provided here for context).

I've tried all sorts of things within this sub, but have settled on showing the simplest example of what, as far as I can understand, should work, but doesn't. Namely, it's that "headers_out" line. It doesn't set a cookie in my browser. I've set my browser to prompt me on and new cookie request, which is popping up new windows all the time, except when I visit my site. Any ideas where I'm going wrong anyone?

All help gratefully received. Thanks, Rob

---
my name's not Keith, and I'm not reasonable.

In reply to Cookies, mod_perl and apache request handlers by reasonablekeith

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.