| PasswordsOne of the interesting properties of CGI scripts is that, even though any user can execute them, there is no way to display them on the screen. e-mail me if you know differently. This means a password script can be as simple as this: #********BEGIN BODY************** if ($value[0] ne "mypassword") {
<BODY BGCOLOR="WHITE"> <H1> Welcome, you have entered the<P>
';
#*********END BODY*************** To use this script, you will need to create an HTML page with a form on it. If the password is the only box in the form, it will be passed to $value[0] when it runs this script. Unlike JavaScript, the user cannot see this source code, so it is safe to use an IF statement at the top of the code. if ($value[0] ne "mypassword") {
In Perl, the IF statement is different, depending on whether you are
comparing numbers or text.
!= is not equal to (for numbers) > is greater than >= is greater than or equal to < is less than <= is less than or equal to If you are comparing text, you use the letters eq to test if two values are equal, and ne to test if they are not equal.
ne is not equal to (for text) The statement above will perform whatever follows it if the user's text is NOT equal to "mypassword."
an ELSE statement, and create an entire page, followed by a close brace } at the end.
<BODY BGCOLOR="WHITE"> <H1> Welcome, you have entered the<P>
';
$myfruit = "apples";
print 'I love \nto eat $myfruit';
The double quotes are much smarter than the single quotes. They
interpreted the \n character into a newline. The double
quotes also replaced the text $myfruit with the contents of the
variable. The single quotes simply displayed the text as it was typed.
This is easier
You can always force the double quotes to ignore a special character by preceding it with a backslash \ character. We COULD have written the print statement this way. print "I love \\n to eat \$myfruit";
IN SUMMARY: Use the single quotes when you are sure you will not want Perl to substitute any special characters. Use double quotes to allow Perl to insert variables and newlines and such.
| ||
| |||
Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room |