I have a question for a school project. How do I do an action when somebody's session gets ended. For instance, I want to delete a file that says a user is logged in when his session ends. If he closes the browser or if he doesn't do any request for a while?
You can do so by writing a custom session handler.
On this site you'll find a proper explanation:
http://phpmaster.com/writing-custom-session-handlers/
However, be aware that 'garbage collection' (cleaning up the file as you want to do) does NOT take place directly after the session was closed!
Php uses a setting 'session.gc_probability' that indicates that once every XXX requests, PHP will look for old/closed sessions and start to do garbage-collection
http://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability
There is no way to track this directly. You could however use a database and store in it the last time the user loaded a page, then run a cron job all X minutes which checks which users haven't done anything in the last Y minutes.