User online state indicator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

User online state indicator

Post by Peuplarchie »

Good day to you all,
I working on a login / logout code, now I need to find out who is online and not.

I was thinking of a javascript which would count time spend on page.

here it is :

Code: Select all

 
 
<SCRIPT LANGUAGE="JavaScript">
 
 
 
<!-- Begin
startday = new Date();
clockStart = startday.getTime();
function initStopwatch() {
var myTime = new Date();
return((myTime.getTime() - clockStart)/1000);
}
function getSecs() {
    var tSecs = Math.round(initStopwatch());
    var iSecs = tSecs % 60;
    var iMins = Math.round((tSecs-30)/60);
    var sSecs ="" + ((iSecs > 9) ? iSecs : "0" + iSecs);
    var sMins ="" + ((iMins > 9) ? iMins : "0" + iMins);
    document.getElementById("timespent").value = sMins+":"+sSecs;
    window.setTimeout('getSecs()',1000);
}
// End -->
</script>
 
 
<BODY onLoad="window.setTimeout('getSecs()',1)">
 
<CENTER>
<FORM>
<input size=5 id="timespent" name="timespent">
</FORM>
</CENTER>
 
 
 


Now I need that for each increment of one minute, a txt file would be update (+1)

Code: Select all

 
 
<?php
$File = "YourFile.txt";
$Handle = fopen($File, 'w');
$Data = "Jane Doe\n";
fwrite($Handle, $Data);
$Data = "Bilbo Jones\n";
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>
 
 

Also

If the txt file reach a count of 15, user get logout automatically.


Can somebody help me include the last 2 point to my javascript code ?

Thanks !
BornForCode
Forum Contributor
Posts: 147
Joined: Mon Feb 11, 2008 1:56 am

Re: User online state indicator

Post by BornForCode »

What you can do is to implement your own session engine and count who is online by counting open sessions.
Post Reply