Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: CGI and Sessions

by dorward (Curate)
on Jul 31, 2006 at 14:26 UTC ( [id://564747]=note: print w/replies, xml ) Need Help??


in reply to CGI and Sessions

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.

  1. Client submits form using POST method (as is proper for changing something in a database)
  2. CGI script processes form request and outputs a 302 HTTP response to redirect the user elsewhere
  3. Client recieves 302 and issues a new request to the server using the GET method.
  4. 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://564747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found