Solved

delete session in perl

Posted on 2013-12-24
4
699 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 78

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 78

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.

726 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