|No such thing as a small change|
Re: One User login at time in perl cgiby blue_cowdawg (Prior)
|on Sep 06, 2011 at 15:28 UTC||Need Help??|
Not sure I understand your rationale. CGI by nature is stateless, meaning in this context that N-number of concurrent connections each capable of logging into your application at the same time. Why you'd want to even try to limit to one user at a time does not make sense to me, but I'll bite.
First off you need to find some way of implementing a sense of state in your application, in spite of the fact I just said CGI is stateless by nature. One way of doing that is through the use of session ids and cookies. (I prefer shortbread, but I digress)
You need to track the session ids somehow and associate those session ids with a userid. Looks like you've attempted to do so given the code you have posted in your original posting. But there's more to the task, you've only just begun.
You may want to use a database for some function of database. I doesn't have to be a relational database such as MySQL, PostgreSQL, Sybase, Oracal, et. al. It can be as uncomplicated as a file in /tmp or /usr/tmp (assuming some form of *nix) where you write the userids and session ids. I'd add one more field to that, last access time/date.
The recorded time/date gives you the means of tracking when the user last took a trip through your application. If for each CGI transaction you update that time and date you can also calculate the last time they were seen in the application. If, for instance, they haven't accessed the application in four hours (you can set that threshold lower or higher) you can then automagically log them out and terminate their session. Banks and other financial institutions do that all the time as a security measure.
I've given you the theory... I'll let you skull out the code. If you can't get it to work, post what you've tried (a bit more detail than what you've got) and we'll look at it for you.
Don't forget to try out some of the wonderful Tutorials we have on this website. They may give you more insight into what you are trying to accomplish.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg