When they log in, store the username in a database/log file, then when they log out have it deleted.
EDIT: just realised this wouldn't work as people could close the browser instead of logging out.
You could possibly use Javascript and the "onExit" body tag.
<script language="Javascript">
function logOut() {
document.write("<script language=\"Javascript\" src=\"file/that/logs/people/out.php?username=username\"> </script>");
}
</script>
<body onExit="logOut();">
file/that/logs/people/out.php?username=username would then contain PHP code that deleted the name from the "logged in" database/log file
My javascript isn't great so it may not be exactly right, but something like that should do the trick.