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

Background: In our utility program, we have just normal perl pages. There are two type of users, Admin and User. If they are trying to login, I need to save the value in session object and redirect to another page. 1. I tried to use just cookies, without using sessions, Here the problem is I can able to set the value first time. But I can't able to delete that(when user logouts, I am keeping empty string there)..my system is behaving something strange. This is simple example, but misbehaving. If I refresh the web page again, then the new value is appearing. 2. By using session, setting value is no problem, but the redirecting, just printing the url on web page.
my $session = session_header;#---by using CGI::Session; if ( $query->param("frmsubmit") ) { $uname = $query->param("uname"); $pwd = $query->param("pwd"); if ($uname eq "AA" && $pwd eq "AA") { $session->param( "usertype", 'admin' ); # store into the session: my $c = new CGI::Cookie(-name => 'plcuser',-value => 'admin', -expires + => '+20m'); print "Set-Cookie: $c\n"; print "Location: $rdurl\n\n"; #print $query->redirect($rdurl); }
Thanks for help

Replies are listed 'Best First'.
Re: CGI PERL - session/cookie set up and redirect
by kwaping (Priest) on Jul 24, 2006 at 18:07 UTC
    Here's an example of how to set a cookie and redirect a browser, using CGI:
    use CGI (); my $cgi = CGI->new(); my $cookie = $cgi->cookie(-name => 'test', -value => '1'); print $cgi->redirect(-uri => 'http://www.perlmonks.org/', -cookie => $ +cookie);

    ---
    It's all fine and dandy until someone has to look at the code.
      Thanks. Till now I am depending on expiration of cookie and trying to change the cookie value to null. Instead of that now I am changing the cookie value to 'none'. Now I can able to find the change without refreshing the page. Thanks for ur help. But same question, can we use session object and try to do the redirection? Any suggestions?
Re: CGI PERL - session/cookie set up and redirect
by rodion (Chaplain) on Jul 24, 2006 at 18:16 UTC
      Thank you Sir, but now looking for set the session value(not normal cookie) and redirect.