http://qs1969.pair.com?node_id=640878

reasonablekeith has asked for the wisdom of the Perl Monks concerning the following question:

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.