Solved

delete session in perl

Posted on 2013-12-24
4
687 Views
Last Modified: 2013-12-28
hi all,

i am using the next code to delete the session ... my problem that i can enter the link

on the url address  after doing logout.... this mean that the session is stell a live!

use CGI::Session qw/-ip-match/;

#$sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
$sid = param('CGISESSID') || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});

# logout and delete session
if(param('delete') eq "true"){
   $session->clear();
   $session->delete;
   $session->flush();

}


note: i am using expire timeout when creating the session:
         $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});                
         $session->save_param($cgi);
         $session->expire(300);
         $sid = $session->id();

please help
thanks.
0
Comment
Question by:weissman
  • 2
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
arnold earned 500 total points
ID: 39739706
You should make sure you have a cron job that goes through deleting session files from /tmp based on file age to deal with sessions that expired where the user did not logout.
As well as make sure not to run out of space or have the wrong data to .....

You might want to refer to
http://search.cpan.org/~sherzodr/CGI-Session-3.95/Session/Tutorial.pm#DELETING_A_SESSION
0
 

Author Comment

by:weissman
ID: 39739729
thanks you very much...

it is strange that i need to delete these sessions manualy ! i have read the link you send  and implement te session according to it .... it is strange that they do not said anything about
cron job!

if i change the session to database or anything else should i need also the cron job or it will
done automaticly.

thanks a lot
0
 
LVL 77

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 39740262
Yes, you would need to have a clean-up process just in case.
i.e. some users instead of loging out, close the browser.
If it is in a database, you could as part of the function to add entries, issue a delete for all expired records.  In this case though, you have to make sure that you continually adjusting the expiration every time the user accesses the data so not to delete the session.

another option if you are getting a new session ID, issue a delete to the database deleting any record with this session ID, then insert your new one.
i.e.
session=new session comes up as SDFSDOI
you would then issue a
delete from sesssion_table where session_table where sessionID='SDFSDOI'
this will mean though that your session_table would grow and include old sessions until such time that a previously issued session ID resurfaces.
The existence of old expired sessions will mean you will have more rows that you need in the database and that may impact performance as well as consume more of your space for storing this data.
0
 

Author Closing Comment

by:weissman
ID: 39744397
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question