Re: [Cgi-session-user] session data not being saved till flushed.
Brought to you by:
sherzodr
From: James.Q.L <shi...@ya...> - 2006-02-12 15:52:20
|
I tried another example and it worked (logged is flushed).. % perl -MCGI::Session -e '{my $s=CGI::Session->new();$s->param("logged",1)}' I am posting my code here and hopefully someone can spot why it doesn't flush in the login subroutine. another question along with the code: in the login sub, if user passes the authentication then calls session method which will create new session and send cookie(since i have SEND_COOKIE on), user will then be redirect to ./ . I am expecting a new cookie will be created when it is redirecting user to ./ but i don't see any cookie in the response header. therefor my script can't recognize the user as a logged in one. what's wrong in the code? ### Base.pm use base "CGI::Application"; sub cgiapp_init { my $self = shift; CGI::Session->name('S'); $self->session_config( CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'/tmp/cgisession'} ], DEFAULT_EXPIRY => '+5m', COOKIE_PARAMS => { -domain => 'dev.example.com', -path => '/', }, SEND_COOKIE => 1, ); $self->dbh_config($self->config_param('sqlite.data_source')); } # Login.pm use base 'Base.pm'; sub setup { my $self = shift; $self->start_mode('show_form'); $self->run_modes('show_form' => 'show_form', 'login' => 'login', 'logout' => 'logout', ); $self->tmpl_path('Login/'); } sub show_form { my $self = shift; my %args = @_; my $query = $self->query(); my $tmpl = $self->load_tmpl('login.tmpl'); $tmpl->param(alert => $args{alert} || $query->param('alert')); return $tmpl->output(); } sub login { my $self = shift; my $query = $self->query(); my $username = $query->param('username'); my $password = $query->param('password'); return $self->show_form(alert => "User name and password are required fields.") unless defined $username and length $username and defined $password and length $password; # check username and password , my $user_id = $self->check_auth($username, $password); # failure return $self->show_form(alert => "Invalid login. The number of failed login attemps is $tries") unless $user_id; # update session if passed. my $session = $self->session; $session->param('_logged_in',1); $session->param('username',$username); # $session->flush(); # won't write to disk unless comment out this line $self->redirect_home; } ############ --- "James.Q.L" <shi...@ya...> wrote: > HI, > > I am using C::S 4.03 and the session data is not saved unless i call flush(). The doc claims > otherwise, "Normally it will be called for you just before the program terminates, or session > object goes out of scope, so you should never have to flush() on your own." > > Originally, I was using it with CGI::Application::Plugin::Session and noticed this behaviour. > then __________________________________________________________ Find your next car at http://autos.yahoo.ca |