Hi monks,
While im not able to use the $q->redirect($q->url()) methode, i have written a small script which creates a token, sends it per hidden-tag, and saves it in a session. On a reload, the session value and the POST-data value are the same, and the script prints an error message. This works quite good, except if you hit the submit-button realy realy fast serveral times in a row -than it complains about a reload which never happend. Does anybody know why this happens?
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);
use Time::HiRes qw(gettimeofday);
use Digest::SHA qw(sha256_hex);
use HTML::Template::Compiled;
my $q = new CGI();
my $token = uniqid();
my $s = new CGI::Session;
my $t = HTML::Template::Compiled->new(path => [ '.' ], filename =>
'test.tmpl', open_mode => ':utf8', tagstyle => [ '+tt' ], defa
+ult_escape => 'HTML_ALL');
$t->param(token => $token);
print $s->header(), $t->output;
check_reload();
$s->param(token => $q->param('token'));
sub check_reload {
if( $q->param('token') && ($s->param('token') eq $q->param('token'
+))) {
print "Error: RELOAD";
}
}
sub uniqid {
my($s,$us)=gettimeofday();
my($v)=sprintf("%06d%5d%06d",$us,substr($s,-5),$$);
$v = sha256_hex($v);
return $v;
}
test.tmpl:
<form action="test.pl" method="post">
<input type="hidden" name="token" value="[%= token%]">
<input type="submit" value="Submit">
</form>
Regars,
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.