bar10der has asked for the wisdom of the Perl Monks concerning the following question:
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...
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 $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;
I am not sure where I am making mistake!!............ ............ 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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cookie problem
by derby (Abbot) on Aug 10, 2004 at 12:07 UTC | |
by bar10der (Beadle) on Aug 10, 2004 at 12:20 UTC | |
Re: Cookie problem
by Velaki (Chaplain) on Aug 10, 2004 at 12:26 UTC | |
by Hero Zzyzzx (Curate) on Aug 10, 2004 at 17:41 UTC |
Back to
Seekers of Perl Wisdom