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

Reference code below...

@ my question area noted in the code... A user will likely have access to multiple sites under each several subdomains/databases. I would like to create a session for each subdomain, containing an accessLevel stored in the paramater of the folderName
ie. $session->param($folderName, $accessLevel);
The session would need to be retrievable by a cgi-bin for the subdomain.
So if the URL is:
http://www.$dbName.mysite.com/$folderName
then the cookie would need to be retrievable by scripts in:
http://www.$dbName.mysite.com/cgi-bin

I was figuring something like a bunch of if statements to determine which subdomain again then adding the param to the appropriate session, based on which subdomain it's for.
Is there a way to create multiple sessions for each user, having multiple sessions being created & modified at the same time?

If so, I'd probably end up just building the sessions in the code, then creating cookies, each cookie referencing a session ID, once all the sessions have been fully created.
I have to figure out how to allow each cookie AND session to be accessible by the scripts.

# NOTE: the value of the following array is pulled # from a field in a table (to determine what the user # has access to/is a member of. The first number is the database/subdo +main # it's located on, the second number is the ID number of the area and +coincidentally # the ID # of the folder the site is contained within, under the subdo +main. my @userCanAccess = (1:2, 1:3, 2:6, 2:9, 1:10); my $dbh = DBI->connect("DBI:mysql:dbname:localhost","username","pw"); foreach my $i (@userCanAccess) { my ($sub, $area) = (split /:/, $i); my $dbName; # dbName is the same as the name as the subdomain if ($sub == 1) { $dbName = 'db1'; } elsif ($sub == 2) { $dbName = 'db2'; } elsif ($sub == 3) { $dbName = 'db3'; } elsif ($sub == 4) { $dbName = 'db4'; }; my $statement = "SELECT folderName, accessLevel, userID, otherColu +mn FROM $dbName.areas WHERE areaID = ?"; my $sth = $dbh->prepare($statement) or die "Can't prepare $stateme +nt: $dbh->errstr\n"; $sth->execute("$i") or die "Can't execute the query: $sth->errstr" +; my @row = $sth->fetchrow_array; my $folderName = $row[0]; my $accessLevel = $row[1]; my $userID = $row[2]; my $otherColumn = $row[3]; my $rows = $sth->rows(); $sth->finish; #### Here is where I run into my question. } $dbh->disconnect;

Any help/feedback would be greatly appreciated!
Steny

Replies are listed 'Best First'.
Re: Session management problem. Multiple Sessions @ one time?
by tachyon (Chancellor) on Jul 02, 2004 at 00:12 UTC

    Provided you are happy to depend on cookies just set a session cookie with the desired path and it will be delivered back to you when you hit that path. If you go to another subdomain you will get a different cookie/sessionID. If you want to set lots of session cookies, all globally accessible set the path as / (root) and they will all be available everywhere. You will then get all the sessid's for that user which can reference any data you care to set.

    cheers

    tachyon