Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

my module is running fine but there are errors
1.when i use my module in cgi program i am not able to the retrieve username where as if i paste the script in the cgi program i am able to retrieve the username

note

the module contains the same script which i am pasting . i just made a new module of it so that i can call it easily where i need session variables

2.where ever i use my module in a cgi script it creates a new sesssion instead of tracking for the existing one

please let me know if i am making any mistake or my approac is wrong

do i use cookies to accomplish the same

module is like this

package raman; use CGI::Carp qw(fatalsToBrowser); #die "Bad error here"; use CGI; use CGI::Cookie; use CGI::Session; $cgi = new CGI; our @ISA = qw(Exporter); my $session_dir = "C:\\raman"; use constant SESSION_COOKIE => "MY_SITE_SIDE"; $sid = $cgi->cookie(SESSION_COOKIE) || $cgi->param("sid") || undef; $session = new CGI::Session("driver:File", $cgi, { + Directory=>$session_dir } ) #incase of any error the session close giving an error or die $CGI::Session::errstr; $cookie = $cgi->param(-name => SESSION_COOKIE, -value => $session->id, #sessiion expires after 3 hours -expires=>"+3h"); $cgi->header(-cookie=>$cookie); #print $cgi->header; #print "Your session id is ", $session->id(); # A cookie is being created which is then being send to the user brows +er #$session->param('username', 'raman'); #$session->save_param($cgi, ["username", "password"]); #print $session->param('username'); #prints raman # this line saves all the available/accessible CGI params $x= $session->save_param($cgi); 1;

the script is like this

#!c:\Perl\bin\perl.exe -w use strict; use CGI::Carp qw(fatalsToBrowser); #die "Bad error here"; use CGI; use CGI::Cookie; use Data::Dumper; use CGI::Session; my $cgi = new CGI; my $session_dir = "C:\\raman"; #Generating a new session #use constant SESSION_COOKIE => "MY_SITE_SIDE"; my $sid = $cgi->cookie(SESSION_COOKIE) || $cgi->param("sid") || undef; my $session = new CGI::Session("driver:File", $cgi, { + #giving the directory where the session var +iables will be stored Directory=>$session_dir } ) #incase of any error the session close giving an error or die $CGI::Session::errstr; my $cookie = $cgi->param(-name => SESSION_COOKIE, -value => $session->id, #sessiion expires after 3 hours -expires=>"+3h"); $cgi->header(-cookie=>$cookie); #print $cgi->header; #print "Your session id is ", $session->id(); # A cookie is being created which is then being send to the user brows +er $session->param('username', 'raman'); #$session->save_param($cgi, ["username", "password"]); #print $session->param('username'); #prints raman # this line saves all the available/accessible CGI params my $x= $session->save_param($cgi);

In reply to Re^2: session module by rjsaulakh
in thread session module by rjsaulakh

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [choroba]: Yes, (...)+ only returns the last match
    [erix]: hmyeah... I guess I'll just have to figure out some other way
    [choroba]: split or while /.../g

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (9)
    As of 2018-01-19 08:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How did you see in the new year?










      Results (216 votes). Check out past polls.

      Notices?