There is a php web application that uses a user authentication and authentication mechanism based on the use of sessions. The user enters the application under his account, where he fills out a form that writes data in mysql db.
In the database there is a field in which the user id is written, which when sending a form is taken conditionally from $_SESSION["user_id"] .
The fact is that when the form is filled for a long time, temporary files with information about the session are periodically killed on the server, and in the absence of additional checks, user_id = 0 is written to the database, which is not good. When adding a check to the script on the form submission, a notification is issued à la “something went wrong” and the user has to log in again and fill out the entire form.
How to avoid such situations?