I agree, but with some alterations.
You should be using session variables to hold user info, from the login process to personalise your site.
If your storing login info then you will also produce a new entry in your database logs. Use the unique key field from this entry as a session variable.
E.g. LogID
Use the javascript onunload command to update the database record entry using UserID LogID.
Database log should be a single entry for this
E.g. LogID autonumber indexed
UserID
LoginTime
LogoutTime
If the session varible is not set then don't update.
For peace of mind set the LogoutTime to the LoginTime or some arbitary value when the user does login, to prevent any errors.