|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi ,
I am using the $ENV{"REMOTE_ADDR"} ...ie { $insertingvalues[1] = $ENV{"REMOTE_ADDR"} <insert into mysql database log table> } to log ip addresses (in mysql) regarding remote users after they log in to my web site. After much fruitless searching , i still don't know how to go about determining if that remote user is still logged in, meaning , their browser is still pointed at my web page (domain). What i want to do is automatically log (in mysql) when the user redirects or goes away from my site. Any ideas on the tracking functionality ? (the mysql and ip i already have - just need to know if he or she is still there) and i dont feel like buying a script today. Thanx again, folks |
|
#2
|
||||
|
||||
|
<< their browser is still pointed at my web page (domain). What i want to do is automatically log (in mysql) when the user redirects or goes away from my site. >> i think it wouldn't be that much easy becuase if client is not making any request to your server you can't update the db.May be you have to find out a way with client side(java script) programming to achive this.
__________________
SR - webshiju.com www.lizratechnologies.com "The fear of the LORD is the beginning of knowledge..." |
|
#3
|
|||
|
|||
|
Hey Shiju,
thanks for the respond. You have given me the basic idea, something whereby i would use javascript... theoretically speaking here is some semicode... ie _> <BODY BGCOLOR=#FFFFFF onLoad="window.setTimeout('updateuser();',30000);"> ...then set the call up recursively... <SCRIPT LANGUAGE="JavaScript"> function myfunc() { // call mysql user table, and log the fact he/she is there document.location.href = "http://myserver/mywebpage/cgi-bin/upate-user.pl?userstatus=loggedin" window.setTimeout('updateuser();',30000); } to first set the timeout period, that would then call a javascript function that would call a perl script that would call the database. Thanx, i will go with this idea/ approach for now. I will post the results.. |
|
#4
|
|||
|
|||
|
what about a javascript onUnload?
not sure if that would work. |
|
#5
|
|||
|
|||
|
Yes i just tried the unload() function, that works very well too (very good call), Mr. unobserved, this is probably the best solution so far. The only caveat , is that you must hold the user back (for 1 more page) , and tell them they have been logged out, i suppose this is the best way- so far.
Even better solution, would be less obtrusive or go undetected as the user is prevented from going straight to his/her new destination... ? Any ideas (ie use the unload() function and then redirect them to their original destination - me thinks thats not possible) The other problem is that you have to put all this code in all your html and perl scripts (a lot of work) , on the client side, this is probably the only way to do this, but if there was a server side solution (ie 1 script), that would be best - again maybe not possible. HMMM, |
|
#6
|
|||
|
|||
|
what about this?
html Code:
<body onUnload="/cgi-bin/userLeaving.pl"> perl Code:
#!/usr/bin/perl use CGI; my $userid = getuserid(); logout($userid); print header(-status=>'204 No Response'); something like that MIGHT work. emphasize might. the only other option would be to breifly open a tiny new window that calls the script and have the ouput from the script do a window.close(); the small new window can even let the user know you are logging them out of the system or something like that. hey, even right when the new window opens you could have a: windor.opener.focus(); which should move the focus back to the main window while the small logout window does it's stuff in the background? lemme know how it works out. |
|
#7
|
|||
|
|||
|
Re: unobserved's method for user detection / loggin
Yah, thanx again for the ideas, A MAJOR thing i overlooked is that ie. WHen a user is in the welcome html page and then they "unload" to a new page .ie mainscreen.html , then the problem is that they got logged. The nature of this is, that the user can leave anytime, you dont know if they are leaving to another web site or just staying at your site and moving to another page/script/location. So when making the call to perl, you must log that each time. I guess what the thing to do , is to keep updating that record , even though they are not logged off, until they actually are logged off. That means at the beginning of each perl script called from an html based page (perl calling perl - really) you must put the call to update mysql . [ the first time they got logged is when the user logs on to your system- and you INSERT a record into mysql's log table]. When the user jumps to another link/url , they will be logged anways - right up until the actual time they leave the site. Again, unobserved, the problem with windows in the back , etc, is that the user may only be moving to let say , the browse.html page. Sure, he has moved to another url, but he has not logged out. Unless he manually decides to logout, all is fine and dandy. Many times a user will not log out manually , and just shut down the browser (so the last log will be the last time that user jumped to that last web page) or move off into the sunset. SUCH is the nature of logging out, hey im sure banks and ie brokerages must have really had some headaches with this one too ! More advice welcome, especially in regard to the entire nature or logic of this problem - ie having a user log in, log his ip address, make sure we know when he has been logged out. thanx, bb |
|
#8
|
||||
|
||||
|
I'm not sure what your objective is, but if it is that you want aggregate stats for site visitors, you could implement it this way:
Create a "click-through" script that serves requests. When called, it determines if a session id cookie exists. If not, it creates one and stores the start time, the IP, the requested page, etc. If yes, it logs the requested page and a timestamp. It then uses $ENV{REQUEST_URI} or some such mechanism to redirect them to the requested page. You could then determine: 1). The length of time the user spent on your site (the last request time - the start time). You could average this for all users. 2). The number of pages visited per user (and averages). 3). The pages visited. etc., etc. I imagine a table structure like this: CREATE TABLE sessions ( id int(11) not null primary key, session_id varchar(128) not null, ip varchar(15) default '0.0.0.0', request_time int(11) not null default '0', page_requested varchar(255), index (session_id, request_time), ); |
|
#9
|
|||
|
|||
|
I posted a solution to this problem in PHP on the DevShed PHP board. Perl programmers should have no trouble following it:
http://forums.devshed.com/showthrea...13462&forumid=5 The idea is simply to decide on an arbitrary time limit from the time a user requests a page to when you can consider them gone. Log all page requests with a timestamp and IP address, and then just count all the distinct IP addresses in the log for the last (5) minutes.
__________________
Please don't visit my lame personal website, www.webhamster.co.uk. Half the time it doesn't even work! |
|
#10
|
|||
|
|||
|
using frames
I'm doing the same kind of thing by using frames. I set a frame to reload every 30 seconds. When the frame reloads, the users_loggedin table is updated and new messages are sent back into this frame. I think you could do the same with an invisible frame.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Determining current users (on your server) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|