[plug] perl question
Anthony J. Breeds-Taurima
tony at cantech.net.au
Tue Aug 20 10:49:04 WST 2002
On Tue, 20 Aug 2002, Patrick Tehvand wrote:
> On Tue, 20 Aug 2002 10:21, Anthony J. Breeds-Taurima wrote:
>
> > We need to see the call in the original script so we can help.
>
> in the main.cgi script:
> <snip>
> require "locked.cgi";
>
> <snip>
>
> print "<table border=\"0\" height=\"100%\" width=\"150\"><tr><td>";
> if (exists($in{username})) {
> &authenticate;
> print "You were authenticated.<br>";
> else {
> print "<table valign=\"bottom\" border=\"0\" height=\"1%\" width=\"150\"><tr><td valign=\"top\">
> <form method = \"post\" action = \"main.cgi\">
> Username <input size=\"19\" type = \"input\" name = \"username\"><br>
> Password <input size=\"19\" type = \"password\" name = \"password\"><br>
> <input type = \"submit\" value = \"login\"></td></tr></table></td></tr>
>
> ";
>
> }
> print <<"EndofHTML";
> <tr valign="bottom" align="right"><td> etc......
>
> is that what you need?
Yup, basically a perl require, is (somewhat) similar to an include statement
in C or PHP. It places the contents of the file (in ths case locked.cgi)
where the require statement is. Any initalisation code is run, vars and subs
are added to the appropriate namespace.
So that means that you are not so much calling a seperate program as running a
subroutine. when that subroutine exits then so doe the whole program
Generally you'd do something like:
sub authenticate() {
if (!$username) {
print "$auth_error10";
return 0;
}
#... more code
return 1;
}
Then you call authenticate as:
if (exists($in{username})) {
if (&authenticate) {;
print "You were authenticated.<br>";
} else {
print "Go away you stinking pig dog!<br>";
}
} else {
# show login form.
}
Or to my way of thinking:
if (exists($in{'username'}) && authenticate()) {
print "You were authenticated.<br>";
} else {
# show login form.
}
HTH
Yours Tony
Jan 22-25 2003 Linux.Conf.AU http://linux.conf.au/
The Australian Linux Technical Conference!
More information about the plug
mailing list