RE: [PHP] online/offline script help!!

From: Date: Fri, 15 Dec 2000 23:30:43 +0000
Subject: RE: [PHP] online/offline script help!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30607@lists.php.net to get a copy of this message
I think you'd run in to the issue that if user =8D is online and reading a page from your site...and then he browses to another one...he can appear online, then off, then online... If you want to keep the status of the user for posting messages etc...I'd suggest popping up a window (*eek!* I know those are EVIL!) say 100px by 50px and set the doc refresh rate to say 30 - 180 seconds which will basically be a loop...this would update your Database...then you'd run a SELECT query to see who's online such as: $timeout = 30; // Number of second until a user is declared "offline", also the will be the page refresh rate... $time = date("Y-m-d h:"); $seconds = date("s"); if(($seconds-$timeout) > 0){ $time .= date("i:s"); }else{ $time .= date("i")-1; $time .= date(":s")-abs($seconds-$timeout); } "SELECT * FROM TheTable WHERE IsOnline >= $time" This code is a little crude but should get the general idea across...one issue would be that the user could close the window *gasp*! A work around for this would be to create an IFRAME on each page (you could easily do this with an include() or require()) which you would set width/height to 0,0 and could hide it in a DIV tag whose visibility property was set to 'hidden' so it don't appear anywhere on the page =) The contents of the IFRAME would be the page that refreshes itself every $timeout seconds...while this approach is kinda 'round 'bout, it seems to work in theory...thought older browsers may not support some of the DIV/IFRAM etc...but given the limited tools which we have...not too shabby if I must say so myself... -sharpie! -Jonathan Sharp Director of Technology - Imprev Inc. Renwick Development Group - Flyerware http://www.flyerware.com/ Phone: (425)688-9200 -----Original Message----- From: Broder B [mailto:broder_b@chello.se] Sent: Friday, December 15, 2000 2:47 PM To: Php General Mailing List Subject: [PHP] online/offline script help!! Yo! I'm working on a script wich will keep track of user online or offline. = When a user logs into a site, the script will register the user with an = unique ID and the time when the user logged in, in a database table. On = further requests from the user on any page of the site a script will = query a database for the users unique id and time. If the ID exists and = it is still valid, the script will update the time column with the = current time. When a user has been inactive (not have had any requests = that have updated the time coumn) the user is seen as offline. My = problem is the time. In the database table the column is of type = DATETIME and I want to know how to figure out if the user is online or = not. The original idea I had is: If table_time is x min older than NOW() = then user =3D offline How can I do this? Answers much appreciated /Broder

« previous php.general (#30607) next »