in reply to Re: How can i access a session(CGI::Session) variable in other forms?
in thread How can i access a session(CGI::Session) variable in other forms?

See also CGI::Session::Tutorial.

But the answer you have already been given is correct. You need some way to 'transfer' the state from one form to the next, the most common way to do this is by using a cookie to carry just the session-id form form to form. You can, if necessary, do this with query strings, but this is somewhat messier and less transparent.

By using a framework such as CGI::Application and the session manager plug-in the whole process becomes even more transaprent.

jdtoronto

  • Comment on Re^2: How can i access a session(CGI::Session) variable in other forms?

Replies are listed 'Best First'.
Re^3: How can i access a session(CGI::Session) variable in other forms?
by simy (Initiate) on May 08, 2006 at 19:10 UTC
    i tried using the "use CGI::Simple::Cookie;" I have tried this way in "form1.cgi"
    $log_ses= new CGI::Session(); $CGISESSID = $log_ses->id(); $cookie1 = new CGI::Simple::Cookie( -name=>'ID', -value=>$CGISESSID );
    In my "form2.cgi" i have used..
    %cookies = fetch CGI::Simple::Cookie; $id = $cookies{'ID'}->value;
    when i try to goto form2.cgi...it gives me the following error in the error log.. Can't call method "value" on an undefined value can someone shoot me an example how to handle cookies for session ids??? thanks, simy
      You might have better success were you to read the documents; a procedure which this node suggests you may have missed. In fact, one could almost conclude from your snippets that there may be a few little points about the relationship between variables and files that has escaped your recall.

      You may also have posed your latest question whilst entertaining a mis-impression of the Monastery: the monks love to help folks learn, but they do NOT comprise a free-coding service.

      But you see you didn't read the documentation. I don't know how CGI::Simple::Cookie works. In fact it doesn't does it? When I look at the documentation for CGI::Simple I see code which is very different to what you have shown us here.

      You errors are very basic. For example, in Form 2 you do not create a valid CGI::Simple object, nor do you attempt to read the cookie correctly. I suggested earlier that you read the documentation for one very sinmple reason, there is simple explanatory code with copious explanatory notes. I do not believe that the monastery was established so that we could run one on one basic programming classes for people who prefer not to RTFM.

      Please go and read the documentation and the tutorial and if you have a further issue and you have tried the sample code, THEN come back and ask a question.

      jdtoronto