Avoid Form from being submitted twice by user with Perl (CGI)

I’m writing a small Perl page that receives a POST method submit. I want to be able to prevent from a single person/computer to submit the form multiple times (to avoid flooding with repetitive submits). But I can’t find any examples or explanations on how to do this in Perl CGI. Could you advise or direct me to some examples? I understand I can use some data from the HTTP header (token?) and/or plant a cookie after the first submit, but I’m not sure how.

Any help will be appreciated. Best Regards, -Arseny


The most simple way of avoiding users clicking the button several times would be to add some Javascript to your page. That would ofc not work for scripts or for i.e. pressing F5.

<input type="submit" name="go" id="go" value="go" onclick="this.disabled='disabled'"/>

You could also write a log file/database on the server that holds the IP address of the user and the timestamp, and check whether he as already submitted. Doing that in addition to setting and checking a cookie is probably the way to go.

For cookies, see cookies in the CGI doc. Simple example:

use strict; use warnings;
use CGI;

my $q = new CGI;

my $submitted = 0;
if ($q->cookie('submitted ')) {
  $submitted = 1;
# Here you could place the file/db check to also set $voted
if ($submitted) {
  print $q->header('text/plain');
  print "You have already submitted!";
} else {
  # Do stuff with the form, like $q->param('foo')...
  # Once you're done, place the cookie
  print $q->header(
    -type   => 'text/plain', 
    -cookie => $q->cookie(
      -name    => 'submitted',
      -value   => 1,
      -expires => '+1y',

Need Your Help

PNG image without border/frame in R?

r image

I am trying to produce a png file that has no black frame around. I know how it works with the plot command, but I cannot find any solution using png() or image(). These are the command lines of co...

Retrieving Medium or Large Profile Image from Twitter with omniauth-twitter

ruby-on-rails-3 twitter omniauth twitter-oauth

I'm using omniauth-twitter gem to authenticate users through twitter. I am also using their Twitter profile image as their avatar for my site. However, the image I get from Twitter is low resolut...