For an affiliate click tracking program, when someone clicks one of our affiliate links, I want to set a cookie that contains a simple integer affiliate_id. I'm using CGI::Application and this is driving me batty. First I tried this (inside a CGI::Application run-mode):
my $url = $cgi->param('url');
my $cookie = $cgi->cookie(
-name => 'affiliate_id',
-value => $aid,
-path => '/',
-domain => $ENV{'HTTP_HOST'},
-secure => 0,
-expires => '+3d'
);
$self->header_add(-cookie => $cookie);
$self->header_add(-redirect => $cgi->redirect($url));
It redirects, but it refuses to set the cookie. I have telnetted in and no cookie header is ever sent.
I also tried this variation:
$self->header_add(-cookie => [$cookie]);
but it made no difference, still refused to set the cookie.
So then, I tried using CGI directly like this:
print $cgi->header(
-cookie => $cookie,
-redirect => $cgi->redirect($url)
);
Same thing happens, no luck with the cookie, although it redirects.
I also tried just setting the cookie and returning nothing from the run mode, and it always prints "1/8" - I have no idea where that is coming from or why it is printing that.
Finally, after running a super search here, I did this:
$self->header_type('redirect');
$self->header_props(
-url => $url,
-cookie => [$cookie] );
This seems to be working fine, but I am wondering why all this is so flaky - I should be able to use header_add() right? And I should be able to print directly as well, right?
Update:
I'm using mod_perl,
CGI.pm version 3.04
CGI::Application Version 3.31
All packaged by debian.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.