Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   storing data in session variable (http://www.go4expert.com/forums/storing-data-session-variable-t1262/)

Rakish 25Aug2006 22:08

storing data in session variable
 
I want to store the username and login_id in the session .

i am tryin to do this.

Code:

$session = $q->cookie(-name=>$session->name,-value=>$session->id); #session cookie
                $session{"username"}  =        $q->param("$usernameVar");
                $session{"login_id"}  =        $q->param("$login_id");
                $cookie13 = $q->cookie(-name=>'login_id',-value=>$login_id); #cookie 1
                print $q->header(-location=>'show_profile.pl',-cookie=>[$cookie13,$session]);

Software error:
Quote:

Global symbol "%session" requires explicit package name at /var/www/cgi-bin/catalog/testlogin.pl line 145.
Global symbol "%session" requires explicit package name at /var/www/cgi-bin/catalog/testlogin.pl line 146.
Execution of /var/www/cgi-bin/catalog/testlogin.pl aborted due to compilation errors.
I have defined the session variable as:

Code:

my $session;
if i just write

Code:

$session = $q->cookie(-name=>$session->name,-value=>$session->id); #session cookie
$cookie13 = $q->cookie(-name=>'login_id',-value=>$login_id); #cookie 1
print $q->header(-location=>'show_profile.pl',-cookie=>[$cookie13,$session]);

it works fine by just sending session cookie to the HTTP header.

Please help.

Rakesh

naveen 26Aug2006 12:56

Re: storing data in session variable
 
Hi,
Code:

$session{"username"}  =        $q->param("$usernameVar");
$session{"login_id"}  =        $q->param("$login_id");

Instead of this, try the following...

Code:

$uname=$q->param("$usernameVar");
$id=$q->param("$login_id");
$session.=$uname.$id;

Keep the rest of the code same.

pradeep 26Aug2006 13:13

Re: storing data in session variable
 
Here is a code snippet which show how to store data into the session.

Code: Perl

use CGI::Session;
 
 $session = new CGI::Session();
 
 #save data to the session
 $session->param('username') = $q->param("$usernameVar");
 $session->param('login_id') = $q->param("$login_id");
 
 #create session cookie
 $session_cookie = $q->cookie(-name=>$session->name,-value=>$session->id); #session cookie
 $cookie13 = $q->cookie(-name=>'login_id',-value=>$login_id); #cookie 1
 
 print $q->header(-location=>'show_profile.pl',-cookie=>[$cookie13,$session]);


Rakish 1Sep2006 20:30

Re: storing data in session variable
 
Thanks Pradeep,


All times are GMT +5.5. The time now is 10:22.