Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How do i know if an user is not on my site anymore??

by pokemonk (Scribe)
on Mar 08, 2001 at 07:09 UTC ( [id://62905]=perlquestion: print w/replies, xml ) Need Help??

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

Well i'm writting a CGI programm that needs to know what users are currently logged on my site, but i'm not sure how to do it. Actually i havo no clue how to do it. i hope the you guys can show me?

Replies are listed 'Best First'.
Re: How do i know if an user is not on my site anymore??
by myocom (Deacon) on Mar 08, 2001 at 07:18 UTC

    The short answer is "you can't."

    This thread has some information on this very topic (I found that node by plugging in 'user "logged in"' in that handy search box up there), and Ovid's response is most educational.

Re: How do i know if an user is not on my site anymore??
by IndyZ (Friar) on Mar 08, 2001 at 11:08 UTC
    Just for the sake of the argument I am going to assume that you want to implement something like the "Other Users" nodelet. There is really no good way to do this. You could make every user log in/out, but users are irresponsible, and would fail to logout.

    The usual method is to log what time the user last accessed a page, and then when you need to generate a list of logged in users, you go through the log diplay only users that have logged in in the last N minutes.

    If you had the times stored in a database you could do:

    SELECT username FROM users WHERE (last_access > $time)
    $time would be the current time minus the "inactivity threshold".

    --
    IndyZ

Re: How do i know if an user is not on my site anymore??
by dws (Chancellor) on Mar 08, 2001 at 11:53 UTC
    There are a couple of ways of telling whether someone is still looking at a page on your site. They're not pretty. Here's one:

    Serve up framed pages. Arrange to "hide" a frame. In that hidden frame, set up a "watchdog timer" using a page with a meta refresh tag to a CGI on your site. The CGI keeps track of who is still out there polling, and returns the same page. After some suitable interval of not getting a poll, mark the user as logged out. You'll also need to use a cookie to distinguish people who may be sitting behind a firewall that's doing NAT (network address translation).

    This works. People will throw bricks at you, but it does work.

Re: How do i know if an user is not on my site anymore??
by dmitri (Priest) on Mar 08, 2001 at 20:12 UTC
    Here are a couple of quite painless ways to do this.

    Solution No. 1
    Create a CGI script that works with a database and returns (prints) an image. Then, in your web pages, you can set up JavaScript code to reload an image (which can be very small) every 15 seconds or so. Now, the image source will be that CGI program. Every time the CGI is invoked, it will log username and time to the database. Now, to find out who is logged in,

    SELECT USERNAME FROM LOGGED_IN WHERE LAST_TIME > NOW() - 15

    The SQL will be db-specific, but you get the point. The good thing about this approach is that you don't need a separate frame. The downside is that you have to know some JavaScript.

    Solution No. 2
    This one includes a Java Applet. On initialization, it can send HTTP request and log the user in. When the user leaves your site or closes his browser, the cleanup procedure is invoked, which can log the user out (delete a record from a database or a file).

    The second way is not very good if someone trips over his powercord, or Netscape crashes. You pick the way to do it.

    $.02

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found