Delete a File in a Directory

Hi guys, there are files that are stored in a certain directory of my web apps. This is for me to monitor who are online users and each file will be deleted upon the logging out of a certain user. However, my problem is, if the user did not logout and simply close browser, I may not be able to unlink the file. How may I be able to unlink it if the user simply close the browser.

what if they don’t close browser but just browse to another site?
delete files after certain timeout, 10 minutes for example.
And use a database for such a monitor.

Timeout? How am I going to implement that timeout? And in what way am I going to monitor each user through database? Is it by registering each user who logs in?

it is exactly the same way as with files. A database record instead of a file created.

And timeout is very easy to implement. You can take a look on the PHP sessions as an example. Each file has modification time. And, I assume, got modified each time then user requests a page. So you can delete files which are older than certain time

Wow…thank so much Shrapnel_N5 for that wonderful idea.:nanaman:

Is there a specific reason why you are using files instead of a database for this data?