http://qs321.pair.com?node_id=713634

shanu_040 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, This is my first question to this forum..And Very hope full that I will be blessed with exact solution. For my application I am setting up cookies using TT2. and It works well in firefox but same code is not working for IE. I have also setting up the cookies through JS again the same issue I can't get the cookies value in IE. Can any body tell me what will be the issue? Thanks

Replies are listed 'Best First'.
Re: IE issues with Cookies
by Corion (Patriarch) on Sep 25, 2008 at 12:55 UTC

    Are you sure that the problem is with your Perl code? If you're setting the cookies via JavaScript then maybe the JavaScript works in FireFox and not Internet Explorer. Verify that the JavaScript works in Internet Explorer and then sniff the traffic that goes over the network from the browsers.

    You don't even show any Perl code so it's quite hard for us to guess at what the cause of your problem might be, but as there are far too many possible causes in your scenario, I can only recommend you to reduce the number of variables by eliminating them one by one.

      #########JS Code##############

      ###########Perl Code:##############
      if (exists $ENV{'HTTP_COOKIE'}) { my $cookies = $ENV{'HTTP_COOKIE'}; my @cookies_record = split(';',$ENV{'HTTP_COOKIE'}); foreach (@cookies_record) { my ($k,$v) = split('=',$_); $k =~ s/ //g; if ($k eq 'Records') { $value = $v; } } } @selected_records = split(',', $value);
      ##############TT2 Code ############
      [% SET subscription = cgi.param('first') %] [% SET subject = cgi.param('second') %] [% SET content = cgi.param('third') %] [% SET resource = cgi.param('forth') %] [% SET saved_search = cgi.param('saved_search') %] [% cookie = cgi.cookie( name = saved_search, value = resource, expires = '+1m', ); cookies.push(cookie) %]
      ###############Perl Code##################
      my $template = $self->load_tt_template('setup_resource_final'); my $setup_resource_final; my @cookies; my $hash = { 'page_header' => $self->page_header(), 'page_title' => $self->page_title(), 'errors' => $submission_errors, 'content' => $self->content(), 'url' => url(), 'cookies' => \@cookies, 'page_footer' => $self->footer(), }; $$hash{'main_search'} = $self->show_main_search(); $$hash{'site'} = $self->current_site()->nuc_code; $$hash{'cgi'} = $cgi; $template->process('setup_resource_final', $hash, \$setup_reso +urce_final); if(@cookies) { @cookies = ('-cookie', [@cookies]); } $output = header(@cookies, '-CHARSET' => 'UTF-8'); $output .= $self->http_header(); $output .= $setup_resource_final; $output .= $self->http_footer();

        I think you'll find you need to set "path" in your cookie..

        [% cookie = cgi.cookie( name = saved_search, value = resource, expires = '+1m', path = '/', ); cookies.push(cookie) %]

        cheers,

        J

Re: IE issues with Cookies
by moritz (Cardinal) on Sep 25, 2008 at 13:03 UTC
    I am setting up cookies using TT2.

    Uhm, TT2 is a template system, you can't set cookies with it.

    I have also setting up the cookies through JS

    So look in your "browser" if the cookie was set. If no, you know that the problem is with your javascript. If yes, use a HTTP recorder to check if the cookie was submitted to your script.

      Hi, It is possible to set the cookies within template system using CGI module..
        Ok, maybe it's possible - but is it a good idea?

        The reason that you use template systems is that you want to separate programming logic from presentation.

        Now when you try to set HTTP headers from within the template you are assuming that the template is called under very specific circumstances, which might make it rather hard to re-use the template from other scripts.