ahref.com > Guides >
Technology
Building a Site Submission Program, Continued
Input Validation
In lines 24-35, the program does some basic checking on the URL and email address which were passed in. If either does not pass the test, it assigns an error message to the variable $output_string, shows that output, and exits the program. For the URL, the program checks to make sure that it starts with "http://". A stricter program might actually try to access the URL, and generate an error if the page is inaccessible. For the email address, the program checks for an @ sign in the address.
24 if ($input_url !~ /^http:\/\//) {
25 $output_string = "<BLOCKQUOTE><H3>Invalid URL</H3>\n";
26 $output_string .= "<P>You input an invalid URL - try again!</BLOCKQUOTE>";
27 &show_output ($output_string);
28 exit;
29 }
30 if ($input_email !~ /@/) {
31 $output_string = "<BLOCKQUOTE><H3>Invalid Email Address</H3>\n";
32 $output_string .= "<P>You input an invalid email address - try again!</BLOCKQUOTE>";
33 &show_output ($output_string);
34 exit;
35 }
|