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

Hi Monks!
I am trying to delete a session without any success, I am wondering where I am doing the wrong thing here since I can't get the session deleted, instead if I refresh the page it creates another session. Here is the code I am using to load this session and delete it if it was working:
#!/usr/bin/perl -w use strict; use CGI::Session ( '-ip_match' ); ... # sessionid value sample: my $sessionid = "cgisess_dd931b714cb6768854c4efee7bc09c4b"; # log out session my $del_session; if($sessionid) { $del_session = CGI::Session->load( "driver:File", $sessionid,{ Dir +ectory => '../sessions' } ) or die CGI::Session->errstr; # Delete session (if open) $del_session->delete() if ($del_session); $del_session->flush() if ($del_session); } ...

Thanks for the help!

Replies are listed 'Best First'.
Re: Delete Session Help!
by Anonymous Monk on Dec 20, 2010 at 15:24 UTC
    post complete code
      OK, here is the code to delete the session(s) I am using:
      #!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use CGI::Session ( '-ip_match' ); use CGI::Carp qw(fatalsToBrowser); use vars qw($q); my $q = new CGI; $| = 1; my $sessionid = param( 'session' ) || ''; my $del_session; if($sessionid) { # here should delete the passed session $del_session = CGI::Session->load( "driver:File", $sessionid,{ Dir +ectory => '../sessions' } ) or die CGI::Session->errstr; # Delete session (if open) $del_session->delete() if ($del_session); $del_session->flush() if ($del_session); print $del_session->header(); print "done"; } else { # here should delete all sessions in directory $del_session = CGI::Session->load( "driver:File", undef,{ Dire +ctory => '../sessions' } ) or die CGI::Session->errstr; # Delete session (if open) $del_session->delete() if ($del_session); $del_session->flush() if ($del_session); print $del_session->header(); print "done"; }
      But it can delete any session! Thanks!
        # here should delete all sessions in directory

        No, that code will not delete all sessions. See CGI::Session Question, use CGI::Session->find( $dsn, sub{}, \%dsn_args )

        Sorry "It can not delete any session!"

        How do you know (how did you check)?

        Sorry "It can not delete any session!"