adi123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I have created session using CGI::Session module.
I have to access the values stored in that session variables in the next page.
Im using $cgi->redirect to go to next page.
but in next page im not able to access the values.
to access the session values I hav used the following code
$sid = $cgi->cookie("CGISESSID") || $cgi->param("CGISESSID") || undef; $session = new CGI::Session(undef, $sid, {Directory=>'ward/cookies'}); $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); print $session->param("s_userid");

"s_userid" is session variable which i have set in the previous page.
but it is printing NULL.
what may be the problem?Pls anyone help me.
Thankx in advance.

Replies are listed 'Best First'.
Re: accesing session variable values
by Happy-the-monk (Canon) on Apr 21, 2004 at 08:41 UTC

    Though I haven't actualy tried it, it looks to me that you have got a number of things wrong.

    Have a look at the CGI::Session::Cookbook, which should make the use of it clear to you (I am currently reading/learning from it).

    Cheers, Sören

Re: accesing session variable values
by knowmad (Monk) on Apr 21, 2004 at 14:19 UTC

    Hi adi123,

    I recently ran into this problem when using CGI::Session while doing a redirect. My solution was to set the cookie before doing the redirect. Apparently, the redirect is happening before CGI::Session is able to set the cookie. Here's the snippet of code that sets the cookie (btw, I'm using CGI::Application so YMMV):

    my $cookie = new CGI::Cookie(-name=>'CGISESSID', -value=>$session->i +d); $self->header_props(-url => $new_url, -cookie => $cookie); $self->header_type('redirect');

    HTH,
    William