Ignoring the security concern about the IP address, here's a somewhat cleaner version of your code. With Perltidy and declaring variables, this only took a few minutes.

#!/usr/bin/perl -w use strict; use CGI qw(:standard); use HTML::Entities; my $myipnumber = "123.45.67.890"; my $full_path = "/htdocs/data"; my $data_file = "update.txt"; checkip(); my @days = ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ); my @months = ( 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december +' ); my ($sec, $min, $hour, $mday, $mon, $year, $wday) =(localtime(time))[0 +..6]; my $time = sprintf( "%02d:%02d:%02d", $hour, $min, $sec ); $year += 1900; my $date_for_logfile = "$mday $months[$mon] $year, $time"; my %formdata = map { $_ => param($_) } param(); my @fieldsnames = keys %formdata; open( RESULTS, ">$full_path/$data_file" ) || die "Couldn't open file: +$!\n"; my $results; while (my ($key,$value) = each %formdata) { print RESULTS "$key=$value&"; $results .= b($key)." - $value". br(); } print RESULTS "updated=$date_for_logfile"; close(RESULTS); encode_entities($results); print header(), start_html(-title => 'Results'), CGI::center( b( 'Your Flash variables created $date_for_logfile :' ), br(), $results ), end_html; exit; sub checkip { unless ( $ENV{REMOTE_ADDR} eq $myipnumber ) { print header(), start_html( -title => "Error!", -bgcolor => "white" ), CGI::center( font( { -face => "Verdana, Arial", -color => "red", -size => "3" }, b("Invalid ip-number") ) ), end_html; exit; } }

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)


In reply to Quick 'n cleaner flash-variables updatescript by Ovid
in thread Quick 'n very dirty flash-variables updatescript by teabag

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.