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

📄 ch17.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 5 页
字号:
&lt;TD VALIGN=TOP ALIGN=LEFT COLSPAN=1&gt;<BR>
&lt;INPUT TYPE=SUBMIT NAME=&quot;submit&quot; VALUE=&quot;Register
a New User&quot;&gt;<BR>
&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;<BR>
&lt;/FORM&gt;<BR>
&lt;HR&gt;<BR>
&lt;FORM METHOD=POST ACTION=$ref_url&gt;<BR>
&lt;TABLE&gt;<BR>
&lt;TR&gt;&lt;TD VALIGN=TOP ALIGN=LEFT COLSPAN=1&gt;&lt;B&gt;Email
Address:&lt;/B&gt;&lt;/TD&gt;<BR>
&lt;TD VALIGN=TOP ALIGN=LEFT COLSPAN=2&gt;&lt;INPUT TYPE=TEXT
NAME=&quot;email&quot;&gt;&lt;/TD&gt;<BR>
&lt;TD VALIGN=CENTER ALIGN=LEFT COLSPAN=1 ROWSPAN=2&gt;<BR>
&lt;INPUT TYPE=SUBMIT NAME=&quot;submit&quot; VALUE=&quot;Registered
Users Proceed&quot;&gt;&lt;/TR&gt;<BR>
&lt;TR&gt;&lt;TD VALIGN=TOP ALIGN=LEFT COLSPAN=1&gt;&lt;B&gt;Password:&lt;/B&gt;&lt;/TD&gt;
<BR>
&lt;TD VALIGN=TOP ALIGN=LEFT COLSPAN=1&gt;&lt;INPUT TYPE=PASSWORD
NAME=&quot;password&quot;&gt;&lt;/TD&gt;<BR>
&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;<BR>
&lt;/FORM&gt;<BR>
&lt;HR&gt;<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
}<BR>
<BR>
<BR>
#<BR>
# a user has asked for a new account.&nbsp;&nbsp;Gives a fairly
random 6 digit<BR>
# number to them as their password via email<BR>
# Also, creates an empty .cdd file -- this file will sort this
users<BR>
# vote information<BR>
#<BR>
sub new_user {<BR>
<BR>
&nbsp;&nbsp;&nbsp;local ($email);<BR>
&nbsp;&nbsp;&nbsp;($email) = @_;<BR>
<BR>
# <BR>
# Trap for no email address entry.&nbsp;&nbsp;It's still very
possible for someone<BR>
# to feed the program a non-existant email address, or a random
string of<BR>
# characters for that matter, but it won't crash the program and
it won't<BR>
# do the offending person any good, either, as their password
will be<BR>
# provided to them by email anyhow<BR>
#<BR>
&nbsp;&nbsp;&nbsp;$email =~ s/\s//g;&nbsp;&nbsp;&nbsp;&nbsp;#
eliminates all whitespace in email address<BR>
&nbsp;&nbsp;&nbsp;if ( $email eq '' ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Content-type:
text/html\n\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;No Email Address was entered&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
Either nothing was entered into the email address field or only
whitespace<BR>
characters were entered.&nbsp;&nbsp;Return to the &lt;A HREF=$ref_url&gt;home
page&lt;/A&gt; of this<BR>
site to re-start the process.<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;} else {<BR>
<BR>
#<BR>
# create a password of 6 mostly random digits... check to see
if a data file <BR>
# with that password already take exists... if so, add one to
the password <BR>
# and check to see if that exists... repeat until available password
is found<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pswd = rand;&nbsp;&nbsp;&nbsp;&nbsp;#
put a random number into pswd<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($pswd,$[,2) = ''; #
remove 2 digits from its front<BR>
# to this number, add the number of seconds since 1970 &amp; the
current PID<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pswd = $pswd + time + $$;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse $pswd;&nbsp;&nbsp;&nbsp;&nbsp;#
reorder string back to front<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($pswd,$[+6) = ''; #
take the first 6 characters<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ( -e ($pswd . '.cdd')
) { $pswd++; } # checks for file Existance<BR>
<BR>
#<BR>
# create the datafile with name &quot;PASSWORD.cdd&quot;<BR>
# Store email address and password as data fields<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$passfilename = $pswd . '.cdd';
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(DF,&quot;&gt; $passfilename&quot;);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print DF &quot;Email Address\t$email\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print DF &quot;Password\t$pswd\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close(DF);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chmod 0660, $passfilename;
<BR>
<BR>
#<BR>
# Send email to new subscriber telling them what their password
is<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(EM,&quot;| /usr/sbin/sendmail
-t&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print EM &lt;&lt;END;<BR>
To: $email<BR>
Cc: $admin<BR>
From: &quot;Richard's Music Database Program&quot;<BR>
Reply-To: &quot;Richard Dice&quot; &lt;rdice\@anadas.com&gt;<BR>
Subject: Welcome, new subscriber!<BR>
<BR>
You are now a subscriber to Richard's Music Database.&nbsp;&nbsp;This
allows you to<BR>
vote on what you think of his music collection.<BR>
<BR>
To access your account, go to:<BR>
&nbsp;&nbsp;&nbsp;$ref_url<BR>
<BR>
Email Address : $email<BR>
Password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $pswd<BR>
<BR>
Hope it's fun for you!<BR>
END<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close(EM);<BR>
<BR>
#<BR>
# Output a message to the Web providing further instructions<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Content-type:
text/html\n\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;<BR>
&lt;HEAD&gt;&lt;TITLE&gt;Welcome, New Registered User!&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
&lt;H3&gt;Welcome, New Registered User!&lt;/H3&gt;<BR>
&lt;P&gt;<BR>
You will be receiving an email shortly which will tell you your
password.<BR>
Once you have that information, please go back to the <BR>
&lt;A HREF=$ref_url&gt;home page&lt;/A&gt; and enter as a registered
user.<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;}<BR>
}<BR>
<BR>
sub view_stats {<BR>
<BR>
&nbsp;&nbsp;&nbsp;$num_votes = 0;<BR>
<BR>
#<BR>
# construct @line array of all cd.txt datafile lines which have
voted-upon<BR>
# albums, and @shortlist array of all such lines which are also
marked<BR>
# as being on the short list (that is, the 3rd datafield is a
&quot;*&quot;).<BR>
# Also, create running total of the number of votes recorded and
the total<BR>
# 0-10 votes submitted <BR>
#<BR>
&nbsp;&nbsp;&nbsp;open(CD,&quot;cd.txt&quot;);<BR>
&nbsp;&nbsp;&nbsp;while ( &lt;CD&gt; ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chop;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/,$_,5);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $field[3] != 0 ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(@line,$_);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$vote_total
+= $field[4];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$num_votes
+= $field[3];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(@shortlist,$_)
if $field[2] eq '*';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;close(CD);<BR>
&nbsp;&nbsp;&nbsp;if ($num_votes != 0 ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$average = $vote_total / $num_votes;
<BR>
&nbsp;&nbsp;&nbsp;} else { $average = 0; }<BR>
<BR>
#<BR>
# order both @line and @shortlist arrays by descending order of
album<BR>
# average vote score<BR>
#<BR>
&nbsp;&nbsp;&nbsp;(@line = sort by_average @line) if defined(@line);
<BR>
&nbsp;&nbsp;&nbsp;(@shortlist = sort by_average @shortlist) if
defined(@shortlist);<BR>
<BR>
#<BR>
# output reports to the Web -- first is total # of voters, then
Average Vote,<BR>
# then table of @line-related information... all pretty straightforward
stuff<BR>
#<BR>
&nbsp;&nbsp;&nbsp;print &quot;Content-type: text/html\n\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;<BR>
&lt;HEAD&gt;&lt;TITLE&gt;Historical Voting Record&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
Here is the historical record of all votes taken regarding Richard's
Music.<BR>
&lt;P&gt;<BR>
END<BR>
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;B&gt;Number of votes cast: $num_votes
&lt;BR&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;printf(&quot;Average Score of Album: %5.2f &lt;/B&gt;\n&quot;,$average);
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;H3&gt;All Albums&lt;/H3&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;TABLE BORDER WIDTH=100%&gt;&lt;TR&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;TR&gt;&lt;TH&gt;Artist&lt;/TH&gt;&lt;TH&gt;Album&lt;/TH&gt;&lt;TH&gt;#
of Votes&lt;/TH&gt;&quot;,<BR>
&nbsp;&nbsp;&nbsp;&quot;&lt;TH&gt;Vote Ave.&lt;/TH&gt;&lt;/TR&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;foreach ( @line ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/,$_,5);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;TD ALIGN=LEFT
VALIGN=TOP&gt;$field[0]&lt;/TD&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;TD ALIGN=LEFT
VALIGN=TOP&gt;$field[1]&lt;/TD&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $field[2] eq '*' ) {
<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$shortcut
= &amp;hash($field[0],$field[1]);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;TD
ALIGN=CENTER VALIGN=TOP COLSPAN=2&gt;&lt;A HREF=\&quot;#$shortcut\&quot;&gt;&quot;,
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;See
Short List&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;TD
ALIGN=LEFT VALIGN=TOP&gt;$field[3]&lt;/TD&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;&lt;TD
ALIGN=LEFT VALIGN=TOP&gt;%5.2f&lt;/TD&gt;&lt;/TR&gt;\n&quot;,
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$field[4]/$field[3]);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;/TABLE&gt;\n&quot;;<BR>
<BR>
#<BR>
# generate &quot;short-list&quot; table... same as above, but
also includes standard<BR>
# deviation in votes.&nbsp;&nbsp;Also, contains &lt;A NAME&gt;
information which is refered<BR>
# to by links in the standard list.&nbsp;&nbsp;This hashing scheme
of <BR>
# &quot;ARTIST _ ALBUM&quot; and then remove all characters not
in the range a-z, A-Z,<BR>
# 0-9 and _ is used as a standard throughout this program to uniquely
<BR>
# identify any album.<BR>
#<BR>
<BR>
#<BR>
# create an array with the file names of all .cdd files within
<BR>
#<BR>
&nbsp;&nbsp;&nbsp;@cddfile = &lt;*.cdd&gt;;<BR>
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;H3&gt;The Short List&lt;/H3&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;TABLE BORDER WIDTH=100%&gt;&lt;TR&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;TR&gt;&lt;TH&gt;Artist&lt;/TH&gt;&lt;TH&gt;Album&lt;/TH&gt;&lt;TH&gt;#
Votes&lt;/TH&gt;&lt;TH&gt;Vote Ave.&lt;/TH&gt;&quot;,<BR>
&nbsp;&nbsp;&nbsp;&quot;&lt;TH&gt;Std. Dev.&lt;/TH&gt;&lt;/TR&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;foreach ( @shortlist ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/,$_,5);
<BR>
<BR>
#<BR>
# Create the standard deviation for an entry in the short list.&nbsp;&nbsp;This
is<BR>
# done using the formula:<BR>
#&nbsp;&nbsp;&nbsp;&nbsp; StDev = ( (1/n) * sigma(i=1,i=n,(VOTE_i
- Average Vote)^2) ) ^ 1/2<BR>
#<BR>
# VOTE_i is determined by parsing each and every .cdd file and
checking for<BR>
# references to the album currently being parsed for<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$stdev = 0;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$n = 0;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$average = $field[4]/$field[3];
<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach $cddf ( @cddfile )
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(CDD,$cddf);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (
&lt;CDD&gt; ) {<BR>

⌨️ 快捷键说明

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