1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

storing data in session variable

Discussion in 'Perl' started by Rakish, Aug 25, 2006.

  1. Rakish

    Rakish New Member

    Joined:
    Jun 30, 2006
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    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:
    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
     
    Last edited: Aug 25, 2006
  2. naveen

    naveen New Member

    Joined:
    Jun 2, 2005
    Messages:
    39
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Calcutta, India
    Home Page:
    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.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Here is a code snippet which show how to store data into the session.

    Code:
    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]);
     
  4. Rakish

    Rakish New Member

    Joined:
    Jun 30, 2006
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Pradeep,
     

Share This Page