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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.