There is the easy way and the hard way.
Easy way: Check concurrency on save with a timestamp.
You can simply add a timestamp (usually named update_at) in your database along with your data.
You put the timestamp in the page (or a $_SESSION variable which is safer) so that when you POST your changes you also post the timestamp. On the server side you verrify if the timestamp in your database is the same as the one you posted and if it's not you return a message saying that the post was editted.
If you care about what the user was typing (and most of the time you should) you can always display both edit side-by-side and allow him to choose/edit one of them.
Hard way: Store lock timestamp in your database
You can add a timestamp with your data the same way as in the easy way (but this time we'll call it last_edit_time).
When a user enters on the edit page you do this:
- You check if the last_edit_time is 30 seconds away from the current time
- If it's been less than 30 seconds you return a message saying the data is being editted
- If it's greater than 30 seconds you set the value of your last_edit_time to the current time and show your edit page
- Once the user is on the edit page you start a javascript interval of 15 seconds
- Every 15 seconds you send an asynchronous request (Ajax) to the server telling it to update the last_edit_time to the current time. We send it every 15 seconds so that if the asynch call takes a long time the user comming to edit right on the 30th second doesn't load the page.
Doing this will assure you that only one user can access the page at the same time. If you want to make it even more secure you would add the user Id next to your last_edit_time to verrify on the moment of saving if it is the same user.
You can even set the last_edit_time to null once the user is done editting. This will unlock the data for everyone as soon as possible.
Of course there can be some edge cases where two users opens the page in the same second. To fix this you can always increase the precision of your timestamp (milliseconds instead of seconds).