One cannot determine the closing of a users session when the browser is closed using the X button. You can put your code in session_End Event to save the changes/user logg off information in the DB.