Keep it server side
Don't ever rely on sessions dying and actually being dead. A lot of times, I start a session, half edit something, head out to lunch, come back, finish the edit and click submit. So what you really need is mid-air collision detection on the server, which is actually fairly easy to accomplish without ever having to worry about sessions.
How you get this is by saving the state of the row in the first page (FORM page), passing that state to the second page (WORK page) and having the second page make sure that state still matches up when it submits.
There are two simple approaches to doing this. The first (which is the easiest to code for, but pretty hard to implement because of all of the database changes), is to tack on a TIMESTAMP column (or your local database equivalent) to the table you are worried about. When you pull up the record in the FORM, also pull up the TIMESTAMP and store it in a hidden varible. When it comes to the WORK page, do your update as usual but add an additional WHERE clause to check that the timestamp is the same as the timestamp that was passed from the FORM page. Check how many rows were updated, if there were 0, you just had a mid-air collision, or the user didn't make any changes and the database noticed that fact.
The second, which is harder to code for but requires no database changes, looks a lot like the first, except that you either pass the whole row through a hidden varible, or a checksum of a serialized version of the row. If you pass a checksum, you either have to lock the tables and manually check the checksum on the WORK page, or have your SQL daemon generate the checksum internally (in a format that could be used for a WHERE clause in an UPDATE statement)
|