Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Listing active sessions in Apache::Session?

by Jeppe (Monk)
on Jan 05, 2004 at 11:23 UTC ( #318813=perlquestion: print w/replies, xml ) Need Help??

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

Fellow Monks,

I have a question. How do I retrieve a list of the active sessions on my web application? I use Apache::Session to manage sessions.

What I wish to achieve is instantaneous changes to a user's access level - instantaneous meaning activated on next page view. So, whenever an administrator alters the access level for a user, the user will not need to log in and out.

  • Comment on Listing active sessions in Apache::Session?

Replies are listed 'Best First'.
Re: Listing active sessions in Apache::Session?
by jdtoronto (Prior) on Jan 05, 2004 at 14:45 UTC
    I don't use Apache::Session, but I do use CGI::Session which is very similar.

    There is no method for retrieving what you want, as others have said. But I have done it using my own code. THese remarks assume you are using a serialisation or storage API which you can easily gain access to. In my case I use MySQL. Here is an outline.

    1. Make sure you have the users id or username saved in the session, NOT IN THE COOKIE!.
    2. Write something which will check for orphan sessions, those which have expired but not deleted, and delete them.
    3. Either:
      • Make sure your code checks the user privileges, which must have been updated somewhere else in the system, each time an access is attempted to a privileged page. or:
      • Store a privileges code in the session (but this should be an unecessary duplicate of info stored elsewhere).

        In my case I also store a '_IS_LOGGED_IN' flag in the session so on each page access I can check users status easily. In essence you want the code to check 'is the user logged in' and 'does he have sufficient privilege for this page' as part of the access to each page.
    These features are certainly some which could be included in a session manager, but it does depend on just HOW you want to use the session manager. As I said earlier, I don't use Apache::Session, in CGI::Session everything you need to implement these additional features is stored in the session record. Such may not be the case in Apache::Session, you will need to check, but the two modules are closely related.

    jdtoronto

Re: Listing active sessions in Apache::Session?
by PodMaster (Abbot) on Jan 05, 2004 at 11:39 UTC
    You don't. Apache::Session provides no API for that sort of thing (you can see that from the pod). If you really want to do it, you'll have to go sourcediving. Did you check cpan to see if there is some extension that will let you do this?

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Listing active sessions in Apache::Session?
by drfrog (Deacon) on Jan 05, 2004 at 14:25 UTC
    interesting , i can see the need for this too!

    couldnt you pull the data straight out of the session database table or file and do all the work on that data that way?
      Yep and thanks. I've changed from Apache::Session::File to Apache::Session::MySQL, and now I can run something like this:
      #!/usr/bin/perl use strict; use warnings; use DBI; use Apache::Session::MySQL; use Data::Dumper; my $db_user = 'root'; my $db_pass = ''; my $dbh = DBI->connect('DBI:mysql:sessions', 'root', ''); my $sth = $dbh->prepare('select id from sessions'); $sth->execute(); while (my $arrayref = $sth->fetchrow_arrayref) { my $id = $arrayref->[0]; my %hash; tie %hash, 'Apache::Session::MySQL', $id, { DataSource => 'dbi:mysql:sessions', UserName => $db_user, Password => $db_pass, LockDataSource => 'dbi:mysql:sessions', LockUserName => $db_user, LockPassword => $db_pass }; print Dumper($hash{$id}); untie %hash; } $sth->finish();
      This is a good step in the right direction, so I think I'm good from here.. It's unfortunate that I need to hack in this ungraceful way, though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://318813]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-01-18 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (54 votes). Check out past polls.

    Notices?