Sessions probably aren't the best solution for this.
In the more general case of protecting against duplicate submissions, I suggest that when you send the form to the client, you include a hidden input containing a unique pseudo-random string (perhaps some combination of the time, the user's ip address and a random number).
Add this to a new column in your database. When the form is submitted, test to see if that value is already in the database. If it is, then you can either update the record or ignore the new data.
In the specific case of dealing with refreshes, use the PRG pattern.
- Client submits form using POST method (as is proper for changing something in a database)
- CGI script processes form request and outputs a 302 HTTP response to redirect the user elsewhere
- Client recieves 302 and issues a new request to the server using the GET method.
- Server responds with a webpage that displays some information to the client.
If the user hits refresh, then they'll just request the GET data again and not repost the submission.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.