in reply to Cookies, how can you set one if it must be done before the header?
Hope that helps...use CGI qw(:cgi); # Name of this script, for example my $script = script_name(); my $query = get_param('action') || 'start';' my %actions = ( start => \&do_start, login => \&do_login ); &{ $actions{$query} } sub do_start { my $cookie = cookie('cookie_name'), # Check $cookie value, note that cookies # aren't to be trusted 100% if($cookie) { showsecretcontent(); } else { show_loginpage(); } } sub showsecretcontent { # prints secret content page } sub show_loginpage { # prints login page # Have a hidden field and set its name as 'action' # and its value to 'login' } sub do_login { # process results do_refresh(); } sub do_refresh { my $cookie = ( -name => 'mycookie', -value => 'youareloggedin', -path=>'/', -expires => '+1y' ); print header (-cookie => $cookie); start_html(); print qq~<META HTTP-EQUIV ="Refresh" CONTENT = "2 ; URL=$script">~; print p("You've successfully logged in. Please wait while you're re- +direced..."); end_html(); }
|
|---|