Hi Monks, I am writing a web based tool using CGI-Application & HTML-Template. I need to recognise re-visiting users. For this I am writing a cookie. So far so good and following code works fine...
my $self = shift; my $query = $self->query(); my $redirectTo = $query->param('redirectTo'); ---- ---- $userDetails='<all info that needs to be stored>'; my $expires = '+12M'; my $kpi_cookie = $query->cookie(-name=>'kpi', + -value=>$userDetails, + -expires=>$expires,); $self->header_props(-cookie=>[$kpi_cookie]); my $template = $self->load_tmpl('index.html'); my $lmess = "Successfully logged in"; $template->param(MSG => $lmess); return $template->output;
However problem comes when I try to redirect user to the section of the website where user intended to go after writing cookie. So for example if user wants to enter/update his monthly report, when he clicks on that link, system should check for existing cookie and if no cookie is found, write cookie and then redirect to 'enter/update data' section. When I try to re-direct immediately after writing cookie, cookie information is lost!! Here is the code-
............ ............ my $redirectTo = $query->param('redirectTo'); my $this_url = $query->script_name(); $userDetails='<all info that needs to be stored>'; my $expires = '+12M'; my $kpi_cookie = $query->cookie(-name=>'kpi', + -value=>$userDetails, + -expires=>$expires,); $self->header_props(-cookie=>[$kpi_cookie]); my $redirect_url=$this_url.'?rm='.$redirectTo; $self->header_type('redirect'); $self->header_props(-url => $redirect_url); return;
I am not sure where I am making mistake!!

In reply to Cookie problem by bar10der

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.