⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13.htm

📁 美国Macmillan出版社编写的Perl教程《Perl CGI Web Pages for WINNT》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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 &quot;guest&quot; with password &quot;guest&quot; is added

to the site's membership database. The HTML for gaining access

to the site is found in the file &quot;access.htm&quot; and looks

like this:

<BLOCKQUOTE>

<PRE>

&lt;HTML&gt;

&lt;TITLE&gt; Goo Goo Records Member Access&lt;/TITLE&gt;

&lt;BODY&gt;

&lt;H3&gt;Goo Goo Records Web Site Member Access&lt;/H3&gt;

&lt;HR&gt;&lt;P&gt;

Please enter your username and password to access the great user stuff....&lt;P&gt;

&lt;FORM METHOD=POST ACTION=&quot;http://www.googoo.com/cgi-bin/pass.pl&quot;&gt;

UserName: &lt;INPUT TYPE=&quot;TEXT&quot; NAME=&quot;name&quot; size=25&gt;&lt;P&gt;

Password: &lt;INPUT TYPE=&quot;PASSWORD&quot; NAME=&quot;password&quot; size=25&gt;&lt;P&gt;

&lt;INPUT TYPE=SUBMIT VALUE=&quot;Enter&quot;&gt;

&lt;/FORM&gt;

If you want to sample our site, enter &quot;guest&quot; as the member name, and &quot;guest&quot; 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 &lt;A HREF=&quot;new_member.htm&quot;&gt;form.&lt;/A&gt;

&lt;HR&gt;

&lt;H3&gt;&lt;A HREF&quot;index.htm&quot;&gt;&lt;IMG SRC=&quot;logo.gif&quot;&gt;Back to the Home Page!&lt;/A&gt;&lt;/H3&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

</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

&quot;pass.pl,&quot; 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 &quot;join.htm&quot;

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(/&amp;/, $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(&quot;C&quot;,hex($1))/eg;

               $FORM{$name}=$value;

          }

          $found=0;

          open(PW,&quot;c:\\googoo\\user.db&quot;);

          while ($line=&lt;PW&gt;) {

               ($name,$pw)=split(/:/,$line);

               if (($name eq $FORM{name}) &amp;&amp; ($pw eq $FORM{password})) {

                    $found=1;

               }

          }

          close(PW);

          if (($found) &amp;&amp; ($FORM{name}=~/guest/i)) {

               print &quot;Content-type: text/html\n\n&quot;;

               print &lt;&lt;EOF;

&lt;HTML&gt;

&lt;TITLE&gt;Goo Goo Guest Access&lt;/TITLE&gt;

&lt;BODY&gt;

&lt;H1&gt;Goo Goo Guest Access&lt;/H1&gt;

&lt;HR&gt;

&lt;P&gt;

&lt;B&gt;

As a Guest to Goo Goo Records Site you can sample new releases, join our mailing list,

and order compact disks!  

&lt;UL&gt;

&lt;LI&gt;Listen to New Sounds

&lt;LI&gt;Check out New Videos

&lt;LI&gt;View the Latest Hype

&lt;LI&gt;Join the Mailing List

&lt;LI&gt;Order Music

&lt;/UL&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

EOF

               exit;

          }

          elsif ($found) {

               print &quot;Location:

http://www.googoo.com/users/userspage.htm\n\n&quot;;

               exit;

          }

          else {

               print &quot;Content-type: text/html\n\n&quot;;

               print &lt;&lt;EOF;

&lt;HTML&gt;

&lt;TITLE&gt;Access Denied&lt;/TITLE&gt;

&lt;BODY&gt;

&lt;H1&gt;Access Denied&lt;/H1&gt;

&lt;HR&gt;&lt;P&gt;

You entered an invalid userid or password.  Please register, or click &quot;back&quot;

and try again.

&lt;/BODY&gt;

&lt;/HTML&gt;

EOF

               exit;

          }

     }

     else { # if there were problems with the form, print an error.

          print &quot;Content-type: text/html\n\n&quot;;

          print &quot;&lt;HTML&gt;\n&quot;;

       	print &quot;&lt;title&gt;Error - Image Map Error&lt;/title&gt;\n&quot;;

       	print &quot;&lt;h1&gt;Error: Image Map Error&lt;/h1&gt;\n&quot;;

      	print &quot;&lt;P&gt;&lt;hr&gt;&lt;P&gt;\n&quot;;

       	print &quot;There was an error with the Image Map. Please\n&quot;;

          print &quot;contact GooGoo Records at &lt;address&gt;&lt;a

href=\&quot;mailto: support@googoo.com\&quot;&gt;support@googoo.com&lt;/a&gt;&lt;/address&gt;\n&quot;;

          print &quot;&lt;/HTML&gt;\n&quot;

          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>

&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt;

Membership Form

&lt;/TITLE&gt;

&lt;/HEAD&gt;

&lt;BODY Bgcolor=&quot;#40E0D0&quot; Text=&quot;#191970&quot;&gt;

&lt;CENTER&gt;

&lt;H1&gt;Welcome to Goo Goo Records!&lt;/H1&gt;

&lt;BR&gt;

&lt;/CENTER&gt;

&lt;HR&gt;

&lt;P&gt;&lt;B&gt;

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!

&lt;P&gt;

&lt;FORM METHOD=&quot;POST&quot; ACTION=&quot;http://www.googoo.com/cgi-bin/member.pl&quot;&gt;

&lt;STRONG&gt;

User Id: &lt;INPUT TYPE=&quot;TEXT&quot; NAME=&quot;id&quot; SIZE=&quot;25&quot;&gt;&lt;BR&gt;

Password : &lt;INPUT TYPE=&quot;PASSWORD&quot; NAME=&quot;pass&quot; SIZE=&quot;25&quot;&gt;&lt;BR&gt;

Favorite Color: &lt;SELECT NAME=&quot;color&quot;&gt;

&lt;OPTION&gt;Red

&lt;OPTION&gt;Yellow

&lt;OPTION&gt;Blue

&lt;OPTION&gt;Green

&lt;OPTION&gt;Magenta

&lt;/SELECT&gt;

&lt;P&gt;

&lt;INPUT TYPE=&quot;SUBMIT&quot; NAME=&quot;Submit&quot;&gt;

&lt;/FORM&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

</PRE>

</BLOCKQUOTE>

<P>

This information goes to the script &quot;member.pl,&quot; which

is listed here:

<BLOCKQUOTE>

<PRE>

#! usr/bin/perl

# member.pl

	print &quot;What is your ID? &quot;;

	$id=&lt;STDIN&gt;;

               print &quot;What is your Password? &quot;;

	$pass=&lt;STDIN&gt;;

	open (MEMBER, &quot;&gt;&gt;member.pl&quot;); 

# open a file with filehandle MEMBER

	print MEMBER &quot;$id&quot;,&quot;$pass&quot;;

chop($id); 

	print &quot;Thank you, $id! Your name has been added to the Member ship Database.\n&quot;;

	close(MEMBER);

	print &quot;What is your ID?&quot;; 

	$id=&lt;STDIN&gt;; 

	open (MEMBER, &quot;member.pl&quot;); 

	while ($line=&lt;MEMBER&gt;) {

        	if ($line eq $id) {

                	print &quot;You are already a member!\n&quot;;

                	close(MEMBER);

              	exit;

     		}

	}

	close (MEMBER);

	print &quot;What is your Member ID? &quot;; 

	$id=&lt;STDIN&gt;;

	chop($id);

	print &quot;What is your password? &quot;;

	$pass=&lt;STDIN&gt;;

	chop($pass);

	while ($line=&lt;MEMBER&gt;) {

 		($mid, $mpass, $gbcolor)=split(':', $line);

        	if (($mid=~/^$id/i) &amp;&amp; ($mpass=~/^$pass/i)) {

         		print &quot;You are already a Member, $id!\n&quot;;

                	close (MEMBER);

                	if ($gbcolor!~/$color/i) {

                  	print &quot;You have a different favorite color!\n&quot;;

                      	print &quot;Your old favorite color is: $gbcolor\n&quot;;

                        print &quot;Your new favorite color is: $color\n&quot;;

                        print &quot;Would you like to change it? &quot;;

                        $input=&lt;STDIN&gt;;

                        if ($input=~/^y/i) {

                          	open(MEMBER, &quot;member.pl&quot;);

                            	undef $/;

                             	$body=&lt;MEMBER&gt;;

                            	$/=&quot;\n&quot;;



	open (MEMBER, &quot;member.pl&quot;);

	while ($line=&lt;MEMBER&gt;) {

        	($mid, $mpass, $gbcolor)=split(':', $line);

        	if ($mid=~/^$id/i) {

                	print &quot;You are already a Member, $id!\n&quot;;

                	

	close (MEMBER);

	open (MEMBER, &quot;&gt;&gt;member.pl&quot;);

	print MEMBER &quot;$newline&quot;; 

	print &quot;Thank you, $id!  Your name has been added to the Membership Database.\n&quot;;

	close(MEMBER);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs=split(/&amp;/, $buffer);

foreach $pair (@pairs) {

	($id,$value)=split(/=/,$pair);

	$value=~tr/+//;

	$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;,hex($1))/eg;

	$FORM{$id}=$value;

}

$id=$FORM{id};

$pass=$FORM{pass};

$color=$FORM{color};

print &quot;Content-type: text/html\n\n&quot;;

print &quot;&lt;HTML&gt;\n&lt;BODY&gt;\n&lt;H3&gt;\n\n&quot;;

$newline=$id.':'.$pass.':'.$color.&quot;\n&quot;;

open (MEMBER, &quot;member.pl&quot;);

	while ($line=&lt;MEMBER&gt;) {

	($mid, $mpass, $gbcolor)=split(':', $line);

	if (($mid=~/^$id/i) &amp;&amp; 	($mpass=~/^$pass/i)) {

		print &quot;You are already in the guestbook, $id!\n&quot;;

		close (MEMBER);

		if ($gbcolor!~/$color/i) {

			print &quot;You have a different favorite color!\n&quot;;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -