So the time just keeps flying by!
This past week has brought up a major problem concerning the user login notification system. When a user logs in the database is updated to reflect a ‘1′ in a field and if that field is ‘1′ then the image in the Friends List changes. If a user clicks the ‘logout’ link when they have finished, the database is updated to reflect a ‘0′ and that changes the image back again.
Now the only problem with that is, that users are lazy… were all guilty of logging out of a site via the close tab/window button on all browsers..
Finding a way to still update the database, even when a user had closed the browser was arduous! firstly I decided to go down the path of javascript, it seemed like it could work but for some codes it would also run if the page was refreshed or a link was used; not very efficient.
So onto trying to find a new way, could AJAX be the solution? after trying that it seemed that AJAX would help do half the job but still if a user closes the tab/window, no script can run due to the page being closed.
It seemed like I would be needing the server itself to be doing the request, bypassing the need for the user to have the page loaded. I had been informed that a Cron Job was needed.
So after copious hours of coding and trial and error I finally have a working script that will log the user out and update the database even if they close tab/window. Happy days.
p.s Also managed to get a very complex SQL query working for the ‘Most Popular’ system.