I am writing a simple script save_me.cgi that can save the data in form.html into a txt (data.txt)file.
But when user click "refresh" button one the browser on page save_me.cgi, the data will be save again in the data.txt.
could someone help me on this issue?
a studpid way might be check the whole file and see any repeat records. but I would try to avoid this if possible.
You may use session (such as CGI::Session) to handle this. Generate a random ID as hidden form parameter in your form, and write it to the session when finished updating the records. Before each save operation, check whether the ID exists in the session. If so, the page has been refreshed; otherwise, commit it.
Form parameters can be refreshed, but session entries are created on the server so they are a reliable source to detect occurrences of page refreshes.