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

I created a simple login script. User can login, browse different pages, do stuff, etc (cookies =)). Anyway, here's my problem. I've been able to code everything myself without problems, except this one thing; logged sessions.

ie. 5 users are logged in, and at the bottom of the main page, it will display all 5 users. That I can do, but when one logs out, I cannot get it updated... (or if that user is no longer on the site) (I just write the user to a log file upon login; that's all...)

Any help would be appreciated. BWT, I am NOT using a DB for this; file handles instead. Not as effective I know, but I still have yet to learn how to use MySQL properly...

Replies are listed 'Best First'.
Re: User sessions logged
by erasei (Pilgrim) on Jun 26, 2003 at 20:13 UTC
    The easiest way would be to place a default timeout per session. For example:

    Consider a user to be logged in for five minutes after they do something. Meaning when a user loads a page, it writes his name to the 'logged in' file. Five minutes later an external script removes him from the list. When he browses another page, it re-adds him back to the 'logged in' file. It's quick and dirty, and isn't very accurate, however it should be accurate enough for what you are wanting to do.

    There are 'better' (better being quoted because what is 'better' is relative to your unique situation) ways of doing it, but the web was designed to be a connectionless medium so trying to track "connections" isn't that easy/accurate.

Re: User sessions logged
by tcf22 (Priest) on Jun 27, 2003 at 01:07 UTC
    Try using CGI::Session. Its easier than rolling your own.

    If this isn't an option, than erasei's idea of expiring sessions is the way to go.