This script I wrote writes a random string as an image and asks the user to type in the digits. I have that down, no problems there. And for variety I added a bunch of offsets for randomity (if infact it's a word :)), so I feel quite proud because I think it loads rather nice. I do have a problem with it though. If you guess the image right or wrong, it will NOT reload the image but it will rewrite a new random $ID. So if the image was 123456789 and you guessed 123456780, it will tell you you're wrong, make a new ID but the image will still print the original string. Can someone point out why this is happening and how I can fix it?
#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; use Image::Magick; print header, start_html('testing'); if (param('submit')) { my $code = param('code'); my $id = param('id'); print "ID: $id<p>"; if($code eq "$id") { print "You entered the correct code, well done<p><p>";} else { print "<font color=red>You have entered the wrong code. Please try ag +ain</font><p><p>"; } } my ($image, $x); $image=Image::Magick->new; $x = $image->Set(size=>'200x50'); $x = $image->ReadImage('xc:white'); warn "$x" if "$x"; my $chars; my @fonts = ("arial.ttf", "georgia.ttf", "verdanai.ttf"); my @chars = ( "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", " +N", "P" .. "Z", "a", "b", "d", "e", "n", "q", "r", 1 .. 9, ); my @yoffset = ("25", "28", "33", "35", "38", "41", "45"); my @pointsoffseth = ("5,30 199,30", "5,35 199,35", "5,40 199,40", "5,2 +4 199,24", "5,20 199,20", "5,42 199, 42", "5,50 199,50", "5, 55 199, 55"); my @pointsoffsetv = ("100,50 100,0", "90,50 90,0", "110,50 110,0", "85 +,50 85,0", "75,50 75,0", "65,50 65,0", "60,50 60,0", "50,50, 50,0", "40,50, 40,0", "25,50 25,0", "20,5 +0 20,0", "15,50 15,0", "10,50 10,0", "5,50 5,0", "115,50 115,0", "120,50 120,0", "125,50 125,0", "130,50 130,0", " +135,50 135,0", "140,50 140,0", "145,50 145,0", "150,50 150,50", "155,50 155,0", "160,50 160,50", "165,50 165,50", + "170,50 170,50", "175,50 175,50", "180,50 180,50", "185,50 185,0", "190,50 190,0", "195,50 195,0", " +199,50 199,0"); my $ID; ### randomize characters $ID = join '', map { $chars[ rand @chars ] } 1..9; ## length -- > by height ^ for (1 .. 3) { my $pointsoffseth = $pointsoffseth[rand @pointsoffseth]; ## Draw horizontal lines $x = $image->Draw( primitive => 'line', points => $pointsoffseth, stroke => 'black', ); } ## Draw verticle lines for (1 .. 6) { my $pointsoffsetv = $pointsoffsetv[rand @pointsoffsetv]; $x = $image->Draw( primitive => 'line', points => $pointsoffsetv, stroke => '#800', ); } my $xoffset = 10; foreach (split //, $ID) { my $yoffset = $yoffset[rand @yoffset]; my $font = $fonts[rand @fonts]; #print "Font: $font"; $x = $image->Annotate( font=>$font, pointsize=>'26', fill=>'blue', text=>$_, x=>$xoffset, y=>$yoffset); $xoffset = $xoffset + 21; warn "$x" if "$x"; } $x = $image->Write('test.png'); warn "$x" if "$x"; print "Image testing<br>"; print "<center><img src=\"test.png\"></center>"; print <<"ALL"; <center> <form action="random.pl" method="POST"> <input type="text" name="code"> <input type="hidden" name="id" value="$ID"> <input type="submit" value="submit" name="submit"> </form> </center> ALL


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to Item not refreshing with the page by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.