As a follow up to some other answers, here is your script rewritten (but untested and not production quality) to use CGI.pm, with security added and comments:
#!/usr/bin/perl -wT use strict; use CGI; my $query = new CGI; my $datafile = "/home/sites/www.yourname.com/users/web/mysites.txt"; use vars qw($title $location $name $url); ############ THE ACTUAL PROGRAM ############ # regex should only allow characters that you # know are acceptable. In this case a-z, A-Z, _, 0-9 # The way we're assigning $1 to $name is called "taint checking" if ($query->param('name') =~ /^(\w+)$/) { $name = $1; } else { # If we got here, there were illegal characters entered (or no cha +racter) &incomplete; } $url = &findurl; if ($url) { # Send 'em where they want to go print $query->redirect($url); } else { # No url, so do something different } ############ FIND URL ############ sub findurl { # always check the return calls on an open open INFO, "<$datafile" or die "Can't open $datafile: $!"; my @information = <INFO>; foreach (@information) { ($title, $location) = split /\|/; } if ($title eq $name) { $url = $location; } close (INFO); return $url; } sub incomplete { print $query->header, $query->start_html(-title => "Incomplete", -bgcolor => "white"), $query->h1("Form not complete"), $query->p(), $query->hr(), $query->p("Sorry, you forgot to enter something."), $query->p("Please hit the back button on your browser and tr +y again."), $query->end_html; exit; }
Note that in the &incomplete sub, we no longer print the HTTP_REFERER. Some Web servers will execute a server side include that's generated from a CGI (though I understand that this isn't common). If that happens, someone could easily spoof the REFERER variable to be an SSI and enter a bogus name. Then, when the &incomplete subroutine prints it out, it will execute whatever the SSI is. Something like <!--#exec cmd="rm -fr /"--> will delete all of the files on the server that your Web server would have the rights to delete (I am assuming that it's a *nix box, and I might have the actual syntax slightly off).

Please see CGI.pm and perlsec for more information on these issues.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.


In reply to (Ovid) Re: Error 404 fix by Ovid
in thread Error 404 fix by koacamper

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.