I have already used CGI::session in my application but as soon as another server request is made for the other page, the session value get re-initialized.
#! /usr/bin/perl -w use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; use File::Listing qw(parse_dir); use CGI::Session; my $htm = new CGI; my %vars = $htm->Vars(); print $htm->header({ -type => "text/html"}); print $htm->start_html( -title => "Welcome", -style=>{'src'=>'../stdbstyle.css'}); if(defined($vars{'file_creation'}) and $vars{'file_creation'} eq 'FILE + CREATION') { fnShowFileCreationForm(); }elsif(defined($vars{'submit_login'}) and $vars{'submit_login'} eq 'Se +nd') { fnSubmitLogin(); }else { fnLoginForm(); } #-------Login Page-------------------------------- sub fnLoginForm { #FORM TO SHOW LOGIN PAGE----- print $htm->start_form({-method=>'post'}), $htm->start_table({-width=>'50%',-height=>'50%',-length=>' +50%',-align=>'center'}); print $htm->Tr({-bgcolor=>'#888888'}, $htm->th({-colspan=>2,-align=>'center'},"LOGIN")); print $htm->Tr({-bgcolor=>'#A8A8A8',-align=>'center'}, $htm->th("Enter username:", $htm->textarea({-name=>'uname',-cols=>'20',-rows=>'1',-default +=>'',-override=>'1'}))); print $htm->Tr({-bgcolor=>'#A8A8A8',-align=>'center'}, $htm->th("Enter Password:", $htm->textarea({-name=>'passwd',-cols=>'20',-rows=>'1',-defaul +t=>'',-override=>'1'}))); print $htm->Tr({-bgcolor=>'#505050'}, $htm->th( $htm->submit({-name=>'submit_login',-label=>'Send'}))); } #-----------------START FUNCTION 'FNSubmitLogin'----------- sub fnSubmitLogin { my $cgi = new CGI; my $session = new CGI::Session(undef,undef,{Directory=>'/tmp/sessions' +}); my $cookie = $cgi->cookie(CGISESSID => $session->id); print $cgi->header( -cookie=>$cookie ); $session->param('user_id',$username ); fnShowMainMenu(); } #----------------------Login Page ends here---------- #-----------------------Main Menu Form--------------------- sub fnShowMainMenu { print $htm->start_form({-method=>'post'}), $htm->start_table({-width=>'100%',-length=>'100%',-align= +>'center'}); print $htm->Tr({-bgcolor=>'#20B2AA', -fontsize=>+50}, print $htm->Tr({-bgcolor=>'#20B2AA'}, $htm->th({-colspan=>3,-align=>'center'},"Select the Task b +y pressing button given below::")); my $username = $vars{'uname'}; print "UserName = $username"; $htm->end_form(); } #--------Main Menu Form ends here--------------------- #-----------File Creation Form starts here-------# sub fnShowFileCreationForm { print "Content-type: text/html\n\n"; my $cgi = new CGI; my $sid=$cgi->cookie("CGISESSID"); my $session = new CGI::Session(undef,$sid,{Directory=>'/tmp/sessions'} +); my $username = $session->param('user_id'); print "Username = $username";

In reply to Re^2: retaining values among server requests by need_help21
in thread retaining values among server requests by need_help21

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.