I have a big issue here, for which I couldn't find an answer anywhere on the web.
I have a basic MVC system, which has 3 components: Model, View and Controller.
I have an index.php file where I'm including everything based on the URI request of the visitor.
The controller connects the View and Model. I'm opening a file on the page load and write a dummy text there. The problem is the following: if I put a sleep(1) into the controller, to delay before loading the page, a visitor can easily hit referesh multiple times.
The file gets opened and the multiple lines are inserted. I have tried to create a session upon file writing and if it exists I don't even run the file writing.
However there is a problem with that. I've refreshed the page multiple times for testing, and even so the session checking is there, the file still gets the multiple lines written in it.
So I guess it gets a simoultanious HTTP request with the refereshing and all of those requests see that no Session variable is set.
After the page has loaded, and I hit refresh it surely doesn't insert any new line, because the session exists. The problem occurs when the visitor refresh the page multiple times at one loading.
Any recommendation to avoid this?