📄 ch13.htm
字号:
In the script there are provisions made for the use of circle
definitions on an image map. This is included in case the Goo
Goo Records' site requires an image map with circular definitions
instead of, or in addition to, the rectangular definitions already
being used with the current image map. This would save having
to rewrite the entire script in the future just to add the circle
to an image map.
<P>
The <I>x</I> and <I>y</I> coordinates for the image map and map
file refered to in this script, mapfile.map, are listed here:
<BLOCKQUOTE>
<PRE>
default index.htm
rect join.htm 0,0 102,50
rect request.htm 102,0 213,50
rect access.htm 213,0 312,50
rect escape.htm 312,0 384,75
</PRE>
</BLOCKQUOTE>
<P>
where a default page is included in the file. Each section of
the image map is assigned its own destination, or HTML document,
to link to.
<H3><A NAME="GuestAccess">
Guest Access</A></H3>
<P>
When new users first find the Goo Goo Records site, and are unsure
whether they want to join, they may enter the site with limited
guest privileges. To set up guest access to the site, the member
name "guest" with password "guest" is added
to the site's membership database. The HTML for gaining access
to the site is found in the file "access.htm" and looks
like this:
<BLOCKQUOTE>
<PRE>
<HTML>
<TITLE> Goo Goo Records Member Access</TITLE>
<BODY>
<H3>Goo Goo Records Web Site Member Access</H3>
<HR><P>
Please enter your username and password to access the great user stuff....<P>
<FORM METHOD=POST ACTION="http://www.googoo.com/cgi-bin/pass.pl">
UserName: <INPUT TYPE="TEXT" NAME="name" size=25><P>
Password: <INPUT TYPE="PASSWORD" NAME="password" size=25><P>
<INPUT TYPE=SUBMIT VALUE="Enter">
</FORM>
If you want to sample our site, enter "guest" as the member name, and "guest" as the
password for a limited tour of our many delights. If you want to apply for your own membership
to the Goo Goo Records site, please submit this <A HREF="new_member.htm">form.</A>
<HR>
<H3><A HREF"index.htm"><IMG SRC="logo.gif">Back to the Home Page!</A></H3>
</BODY>
</HTML>
</PRE>
</BLOCKQUOTE>
<P>
This creates a page that resembles Figure 13.5, where the new
user is asked to enter his or her member name and password.
<P>
<A HREF="f13-5.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-5.gif"><B>Figure 13.5 :</B> <I>Entering the user name and password</I>.</A>
<P>
The information given in this form is sent to the Perl script
"pass.pl," which is listed in the next section. If the
new user tries out the guest membership, they will be limited
to some areas of the site. An example of a restriction applying
to guest access is an inability to enter the Goo Goo Records'
Trivia Quiz for the chance to win prizes.
<H3><A NAME="MemberAccess">
Member Access</A></H3>
<P>
Users who have already registered by visiting "join.htm"
can gain full access to the Goo Goo Records Web site by entering
their member ID and password. When this data is sent to the Goo
Goo Records' Web server, a CGI script checks the membership database
to see if they are indeed registered, and provides them with the
access granted to a member, which is almost the entire site. The
script that checks for membership runs like this:
<BLOCKQUOTE>
<PRE>
#!/usr/bin/perl
# pass.pl
# The user.db file has entries such as:
# guest:guest
# jonathan:mypassword
# joe:birthday
# This is not really security, this only makes
# the site more
# difficult to get the pages. It is much more complex to have authentication
# on every page without having to enter the password everytime
######################################################
if ($ENV{'REQUEST_METHOD'} EQ 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, $buffer);
# This is the Name-Value pair splitter.. Put into $FORM array
foreach $pair (@pairs) {
($name,$value)=split(/=/,$pair);
$value=~tr/+/ /;
$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$FORM{$name}=$value;
}
$found=0;
open(PW,"c:\\googoo\\user.db");
while ($line=<PW>) {
($name,$pw)=split(/:/,$line);
if (($name eq $FORM{name}) && ($pw eq $FORM{password})) {
$found=1;
}
}
close(PW);
if (($found) && ($FORM{name}=~/guest/i)) {
print "Content-type: text/html\n\n";
print <<EOF;
<HTML>
<TITLE>Goo Goo Guest Access</TITLE>
<BODY>
<H1>Goo Goo Guest Access</H1>
<HR>
<P>
<B>
As a Guest to Goo Goo Records Site you can sample new releases, join our mailing list,
and order compact disks!
<UL>
<LI>Listen to New Sounds
<LI>Check out New Videos
<LI>View the Latest Hype
<LI>Join the Mailing List
<LI>Order Music
</UL>
</BODY>
</HTML>
EOF
exit;
}
elsif ($found) {
print "Location:
http://www.googoo.com/users/userspage.htm\n\n";
exit;
}
else {
print "Content-type: text/html\n\n";
print <<EOF;
<HTML>
<TITLE>Access Denied</TITLE>
<BODY>
<H1>Access Denied</H1>
<HR><P>
You entered an invalid userid or password. Please register, or click "back"
and try again.
</BODY>
</HTML>
EOF
exit;
}
}
else { # if there were problems with the form, print an error.
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<title>Error - Image Map Error</title>\n";
print "<h1>Error: Image Map Error</h1>\n";
print "<P><hr><P>\n";
print "There was an error with the Image Map. Please\n";
print "contact GooGoo Records at <address><a
href=\"mailto: support@googoo.com\">support@googoo.com</a></address>\n";
print "</HTML>\n"
exit;
}
</PRE>
</BLOCKQUOTE>
<H3><A NAME="MembershipApplicationForm">
Membership Application Form</A></H3>
<P>
The staff at Goo Goo Records realized that they wanted to develop
a specific mailing list for each of their bands by requiring users
to become registered members of their site. Membership is free
of charge, and the information garnered from the membership application
form, shown in Figure 13.6, goes straight to the marketing and
publicity databases.
<P>
<A HREF="f13-6.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-6.gif"><B>Figure 13.6 :</B> <I>Membership application form</I>.</A>
<P>
The HTML for this form is as listed:
<BLOCKQUOTE>
<PRE>
<HTML>
<HEAD>
<TITLE>
Membership Form
</TITLE>
</HEAD>
<BODY Bgcolor="#40E0D0" Text="#191970">
<CENTER>
<H1>Welcome to Goo Goo Records!</H1>
<BR>
</CENTER>
<HR>
<P><B>
So you want to join up, eh? move to the head of the class and please enter this short
form and send it in. Your choice of member name and password will be checked, and then
okayed. As soon as you receive confirmation of your id and password, your membership
is active!
<P>
<FORM METHOD="POST" ACTION="http://www.googoo.com/cgi-bin/member.pl">
<STRONG>
User Id: <INPUT TYPE="TEXT" NAME="id" SIZE="25"><BR>
Password : <INPUT TYPE="PASSWORD" NAME="pass" SIZE="25"><BR>
Favorite Color: <SELECT NAME="color">
<OPTION>Red
<OPTION>Yellow
<OPTION>Blue
<OPTION>Green
<OPTION>Magenta
</SELECT>
<P>
<INPUT TYPE="SUBMIT" NAME="Submit">
</FORM>
</BODY>
</HTML>
</PRE>
</BLOCKQUOTE>
<P>
This information goes to the script "member.pl," which
is listed here:
<BLOCKQUOTE>
<PRE>
#! usr/bin/perl
# member.pl
print "What is your ID? ";
$id=<STDIN>;
print "What is your Password? ";
$pass=<STDIN>;
open (MEMBER, ">>member.pl");
# open a file with filehandle MEMBER
print MEMBER "$id","$pass";
chop($id);
print "Thank you, $id! Your name has been added to the Member ship Database.\n";
close(MEMBER);
print "What is your ID?";
$id=<STDIN>;
open (MEMBER, "member.pl");
while ($line=<MEMBER>) {
if ($line eq $id) {
print "You are already a member!\n";
close(MEMBER);
exit;
}
}
close (MEMBER);
print "What is your Member ID? ";
$id=<STDIN>;
chop($id);
print "What is your password? ";
$pass=<STDIN>;
chop($pass);
while ($line=<MEMBER>) {
($mid, $mpass, $gbcolor)=split(':', $line);
if (($mid=~/^$id/i) && ($mpass=~/^$pass/i)) {
print "You are already a Member, $id!\n";
close (MEMBER);
if ($gbcolor!~/$color/i) {
print "You have a different favorite color!\n";
print "Your old favorite color is: $gbcolor\n";
print "Your new favorite color is: $color\n";
print "Would you like to change it? ";
$input=<STDIN>;
if ($input=~/^y/i) {
open(MEMBER, "member.pl");
undef $/;
$body=<MEMBER>;
$/="\n";
open (MEMBER, "member.pl");
while ($line=<MEMBER>) {
($mid, $mpass, $gbcolor)=split(':', $line);
if ($mid=~/^$id/i) {
print "You are already a Member, $id!\n";
close (MEMBER);
open (MEMBER, ">>member.pl");
print MEMBER "$newline";
print "Thank you, $id! Your name has been added to the Membership Database.\n";
close(MEMBER);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, $buffer);
foreach $pair (@pairs) {
($id,$value)=split(/=/,$pair);
$value=~tr/+//;
$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$FORM{$id}=$value;
}
$id=$FORM{id};
$pass=$FORM{pass};
$color=$FORM{color};
print "Content-type: text/html\n\n";
print "<HTML>\n<BODY>\n<H3>\n\n";
$newline=$id.':'.$pass.':'.$color."\n";
open (MEMBER, "member.pl");
while ($line=<MEMBER>) {
($mid, $mpass, $gbcolor)=split(':', $line);
if (($mid=~/^$id/i) && ($mpass=~/^$pass/i)) {
print "You are already in the guestbook, $id!\n";
close (MEMBER);
if ($gbcolor!~/$color/i) {
print "You have a different favorite color!\n";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -