Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:18:39+00:00 2026-06-05T16:18:39+00:00

I need to store a login session when the user is login and remove

  • 0

I need to store a login session when the user is login and remove the login session when the user has logged out of the system or the session has timeout. I am coding in Perl. I know I can use CGI::Session module in Perl but how do I make sure that the session is created by 1 cgi script and removed by another cgi script. Then all other pages of the system has to check if the session exist before it can display its contents.

Currently, I am using the following code to create a new session when the user has login successfully.

my $session = CGI::Session->new();
my $CGISESSID = $session->id();

However, how do I log the user out of the session in another cgi script? I doubt I can just use the following since the $session is not defined in the other cgi script

$session->delete();
$session->flush();

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:18:40+00:00Added an answer on June 5, 2026 at 4:18 pm

    CGI::Sessions are independent of script by default. So you should be able to do just that.

    Just don’t forget to persist the session ID on the client in some way. It can be done with a cookie, see session header() for example. The ID and the session object will be retrieved automatically (if saved properly).

    See CGI::Session new()

    If called without any arguments, $dsn defaults to driver:file;serializer:default;id:md5

    and CGI::Session::Driver::file.

    You can configure them to use the store and settings that you prefer.


    Basic example CGI script using sessions:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    use CGI;
    use CGI::Carp qw(fatalsToBrowser); # show errors in browser
    use CGI::Session;
    
    
    # new query object
    my $q = CGI->new();
    
    # new session object, will get session ID from the query object
    # will restore any existing session with the session ID in the query object
    my $s = CGI::Session->new($q);
    
    
    # print the HTTP header and set the session ID cookie
    print $s->header();
    
    
    # print some info
    
    print "<pre>\n";
    
    print "Hello!\n\n";
    printf "Your session ID is: %s\n", $s->id;
    printf "This sessin is: %s\n", $s->is_new ? 'NEW': 'old';
    printf "Stored session 'test' value: '%s'\n", $q->escapeHTML($s->param('test'));
    printf "CGI Params: %s\n", join ', ', $q->param;
    
    
    # handle the form submit
    
    if(defined $q->param('save')){
        # save param value in the session
        $s->param('test', $q->param('test'));
        printf "Set session value: '%s'\n", $q->escapeHTML($s->param('test'));
    }
    elsif(defined $q->param('delete')){
        # delete session
        $s->delete;
        print "Session will be deleted.\n";
    }
    
    print "\n</pre>\n";
    
    
    # simple HTML form
    
    printf <<'_HTML_', $q->escapeHTML($s->param('test'));
    <hr/>
    <form>
    Session value "test": <input type="text" value="%s" name="test"/>
    <button type="submit" name="save">Save Value</button>
    <button type="submit" name="delete">Delete session</button>
    </form>
    _HTML_
    
    # eof (linebreak needed after _HTML_)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store user credentials in my app. I can store and retrieve
I need to transfer the user session across servers. ie. If user logged in
I am developing a PHP-based login system. Each user has an ID(a number) and
When user is logged in we store its user id in the session. session[:user_id]
I need store just 10 arrays in my app, which I can change from
I'm trying to figure out if it is better to store my user's data
After going back to one of 'PHP Login System' test projects, I now need
After a successful login via Devise, how can I redirect the user back to
How to create a custom login system with google-app-engine's User class? I'm making my
Just wondering what the best way to store user login data on successful login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.