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!!