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

Hello Monks,

I am trying to create more than one cookie but whichever is set first that is remaining as the cookie and other is getting printed on the screen at the top.So what should I do to have more than one cookies. Since this is existing application on which I am working on I donot want to disturb the one which application is already using.
So guide me to right approach.

Blazix

Replies are listed 'Best First'.
Re: Cookies In Perl
by Joost (Canon) on Jul 20, 2004 at 13:49 UTC
Re: Cookies In Perl
by ccn (Vicar) on Jul 20, 2004 at 13:44 UTC
Re: Cookies In Perl
by b10m (Vicar) on Jul 20, 2004 at 21:26 UTC

    Some sample code of how you try to set your cookie(s) would be helpful. I'm guessing you use CGI. If you print them "manually", make sure you don't return an additional \n after the first one. In case of the CGI, this is written in the documentation:

    To create multiple cookies, give header() an array reference:
    $cookie1 = $query->cookie(-name=>'riddle_name', -value=>"The Sphynx's Question"); $cookie2 = $query->cookie(-name=>'answers', -value=>\%answers); print $query->header(-cookie=>[$cookie1,$cookie2]);
    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Cookies In Perl
by Anonymous Monk on Jul 20, 2004 at 16:09 UTC
    Here is code which already exists can you tell me how can I add the cookie when user changes some information in his session. As you Can see the script it does some calls to db and reloads the page setting the cookie if I want to add some value to $sessionInfo variable and change only that value i cannot. please tell me how to proceed ?
    sub setCookie { use CGI qw(:standard); local $username = shift; local $password = shift; local $path = shift; my $sProjName = shift; local($sessionInfo, @UserInfo, $sql, $rec, $value, $iUID, $sUNAME, $iTID, $sTNAME,$iEID, $sENAME, $rc); my $sWorkbenchDSN; # Using the project name, retrieve the proper ODBC datasource name + from the INI file. $sWorkbenchDSN = &getIniKeyValue($sProjName, "dsn", $WB_INI_FILENA +ME); $DBUserName = $username; ##Rel 3.3 - PIM 19986 $username = removeSpecialChar($username); if ($username, $password) ## checks for username and password { local ($error); $error = ""; my $db = OpenDatabaseConnection($sWorkbenchDSN); ### Query User ID and Password $sql = qq| SELECT M.MemberID, M.MemberName, M.PrimaryTeamID, T.TeamName, M.PrimaryEventID, E.EventName, M.PrimaryAreaID, A.AreaName, M.ExpDate FROM tblMember M, tblTeamMember TM, tblTeam T, tblEvent E, tblArea A WHERE M.MemberID = TM.MemberID AND M.PrimaryTeamID = T.TeamID AND M.PrimaryEventID = E.EventID AND M.PrimaryAreaID = A.AreaID AND M.Status != 'INACTIVE' AND M.MemberName = '$username' AND M.Password = '$password'; |; my $sth; # Prepare SQL statement unless($sth = $db->prepare($sql)) { $error = 1; $sth->finish; $db->disconnect; &login($path, $error); exit; } # Execute the SQL statement $rc = $sth->execute; # Check to see if username and password are correct if ($rc != -1) { ########################################################## +################## ## level 2 admin ########################################################## +################## ### Query User ID and Password $sql = qq| SELECT M.Status FROM tblMember M WHERE M.MemberName = '$username' AND M.Password = '$password'; |; my @User = &executeSQLStatement($sql); if ($User[0] eq 'ACTIVELEVEL2') { $sessionInfo = "$iUID|ADMIN|0|0|0|0|" . "0|0|$sWorkbenchDSN|$sProjName"; ### If user's password is default (password), force ch +ange if (($password eq 'PASSWORD') || ($password eq 'passwo +rd')) { $sth->finish; $db->disconnect; my $project = $in{'Project'};