Felix Natter <fn*****@gmx.ne t> wrote in message news:<m3******* *****@werkstatt 4.ldc>...
I would like to lock a record so that when one user is modifying a
particular record, then it is locked for all other users. For this
purpose, I have two fields in every table ("LockedBy int null", which
contains the UserID of the editing user and "LockedSinc e int not
null", a timestamp).
My current logic is: when the user enters the form to modify a record,
lock it (set LockedBy=$UserI D). when the user presses the submit-button
to commit his/her changes, unlock the record.
The problem with this is that the user may press fwd+back buttons of
the browser. So either I find a way to disable these in the
editing-forms or I need to find a different way to do this
If you really need locking then perhaps you need to use a different
backend database that does support row locking otherwise the best
you'll ever achieve is a kludge.
If you have problems with your 'locks' being released you could add to
your logic that a lock can't be held if the user has moved off that
page. It would still mean that if the user clicks on edit and then
goes to lunch, goes home or closes their browser the lock would still
be active.
If you wanted to get really fancy you can have a page that constantly
reports the page is open and the lock is still required.
You place a 1px by 1px image in the page but change the source to
refer to a PHP page, i.e. keeplock.php. You then add some JavaScript
to the page that reloads the image every 30 seconds or so.
In the keeplock.php, you update your locking field to reflect the new
time and then send a header ("image/gif") and the contents of a blank
1px by 1px gif.
If the browser does go back or shutdown the lock will not be updated
and you can safely release the lock.
It still doesn't help if they leave the edit page on their browser
when they go to lunch or go home but a smack round the head with a
large wet tuna may help to remedy that problem.
Paul