The Little Guy Posted July 18, 2008 Share Posted July 18, 2008 Any way I can run a PHP file, when a user navigates away from a page? Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/ Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 If the user has javascript enabled you could call a page, via the onunload() function, however there may be better solutions. What are you trying to do? Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592939 Share on other sites More sharing options...
The Little Guy Posted July 18, 2008 Author Share Posted July 18, 2008 What I am doing, is when a user goes to edit a file, the file gets locked to everyone else. When the file is done being edited, I want the file the be unlocked (by file I mean a cell in the database). so if someone closes the page, I would like to unlock the file. Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592945 Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 I think the best way would be via an AJAX heartbeat of sorts, where you will have a field on your database that shows what time it was 'checked out' and use AJAX to post back an update every so often, say 30 seconds. When a user wants to open that file you will check to see if it has been more then 30 seconds since the 'checked out time' and if it has then the user is no longer editing the file. Then when a user saves or cancels (but remains on the page) you will set the 'checked out time' to somthing like Linux Epoch (Jun 1st 1970) for example. Here are an example: http://ajaxpatterns.org/Heartbeat and a quick google for 'ajax heartbeat' returns Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592952 Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 As an after though you could also use this heartbeat to auto save any changes that a user is in the process of changing, in case their browser crashes. Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592954 Share on other sites More sharing options...
The Little Guy Posted July 18, 2008 Author Share Posted July 18, 2008 I was able to do it using AJAX "onunload", but I have to refresh the previous page that showed the edit button, for the edit button to re appear. Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592963 Share on other sites More sharing options...
The Little Guy Posted July 21, 2008 Author Share Posted July 21, 2008 Bump Link to comment https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-595722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.