I'm not even sure if this is possible, but basically, when a user leaves my site, i'd like to execute some PHP code (say, delete from mysql database for example) Is this even possible?
The best idea here would be to set a session and then set it to class a user as exited if he does not change page or do anything within X mins, somewhat like what VB does with user logged in.
Why you want to delete the data after user quit from your site? If those data which are useless don't store in database store it in cookies deleting data from database each and every time time you are creating pressure to your mysql server. If number of user is less for your website then it is ok. But for mass user deleting data from database is not good what I think.
That depends on what he is storing and who he wishes to have access to the information. Though there are better ways of doing it, say he wants to ensure that a user does not perform an action three times within a browser session based on a user's IP... this information would be pretty useless to store in a database for long term, however it would be unreasonable to store it in a cookie because this would open the application up to cookie tampering and would therefore render the restriction useless. As a solution he could then store the information in the database and remove it when the user exits out. Though a temporary table, or some equivalent may be more suitable.
You can do that using one of those "exit popup" javascripts and initiating an XMLHTTP request to a php file that does what you want to do
Hmm, i actually think cron would be what i need, but i've never used it before so i'll have to go out and learn it I've realised that simply having it on exit wouldn't work because i need my users to refresh the window: http://www.emailondemand.info
You could try make javascript to forge http request after window close to a .php file. This works IF visitor/user has JS enabled.