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

Hi, I wrote script that: validate login from html form, create cookie an than redirect browser to some URL- standard function. I am using CGI so here is part of my code:

use CGI; $query = new CGI; ...................... $cookie = $query->cookie(-name => $cookie_name, -expires => $cookie_expires, -domain => $cookie_domain, -path => $cookie_path, -value=>{ username => $username, password => $crypt_password } ); print $query->header(-cookie=>[$cookie]); ...................... print $query->redirect( -location=>'http://my.domain.cz/', -method=> 'get' );

An here is IMHO problem. Because ther was already printed header, redirect in not functional. Is there any way how to both sen cookie and also redirect after it? THX. Litin Li Tin O've Weedle
mad Tsort's philosopher

Replies are listed 'Best First'.
(Ovid) Re: CGI.pm: cookie AND redirect
by Ovid (Cardinal) on Mar 23, 2001 at 19:24 UTC
    Incidentally, be careful if you want to set a cookie and use a redirect if you are using IIS. I've had some nasty bugs with this only to discover that IIS ignores the cookie on a redirect. More quality control from M$ (click the M$ link. Trust me). It wouldn't be so annoying except that they've had this problem for versions 3.0, 4.0 AND 5.0. Sheesh. You need to use NPH scripts to get around that.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: CGI.pm: cookie AND redirect
by voyager (Friar) on Mar 22, 2001 at 06:19 UTC
    this should do it
    print $q->redirect( -uri => $url , -cookie => $cookie );
      oops, need to print the results of redirect:
      print $q->redirect( -uri => $url , -cookie => $cookie );