📄 ch14.htm
字号:
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192>SERVER_NAME</TD><TD WIDTH=384>The server's host name, DNS alias or IP address, in the form it would appear in a self-referencing URL.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192>SERVER_PORT</TD><TD WIDTH=384>The port number to where the client's request was sent.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192>SERVER_PROTOCOL</TD><TD WIDTH=384>The name/version of the server's information protocol.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192>SERVER_SOFTWARE</TD><TD WIDTH=384>The name/version of the information server software that answered the client's request.
</TD></TR>
</TABLE></CENTER>
<P>
<P>
These environmental variables are a subset of the standard CGI
designated environmental variables for HTTP service.
<H3><A NAME="Browsers">
Browsers</A></H3>
<P>
It is an incorrect assumption that all the people using the Web
do so through Netscape Navigator. While this is by far and away
the most widely used Web client, or browser, it is not the only
one. Microsoft's Internet Explorer is one of several other browsers
growing in use. Both Navigator and Explorer use HTML tags not
supported by the protocol's standards, and that can't be utilized
by the other's software. This means that your site may look different
to different users and their different browsers. To avoid the
problem of having users find your Web site out of sync with their
browser, keeping tabs on which browsers are accessing your Web
site is invaluable.
<P>
The Goo Goo Records site has added an element so they can determine
which browsers are accessing their site, and at what percentage.
Eventually they plan to have special pages for each different
browser, making use of each browser's strengths.
<P>
The following script snippet records which browsers are used to
access the Web site:
<BLOCKQUOTE>
<PRE>
open(TRACK2,">>c:\logs\browsers.trk");
print TRACK2 "$ENV{'HTTP_CLIENT'}\n";
close(TRACK2);
</PRE>
</BLOCKQUOTE>
<P>
This Perl snippet prints the browser type to the file browsers.trk.
<H3><A NAME="IPAddressesDomainNames">
IP Addresses/Domain Names</A></H3>
<P>
The IP address, and the related InterNIC domain name, is the way
computers find each other on the Internet. This series of four
numbers separated by three periods gives each computer on the
Internet, which includes the Web, its own identity. Domain names
are character equivalents that are assigned to these numbers.
For more details concerning IP addresses and domain names, check
out the InterNIC site at
<BLOCKQUOTE>
<PRE>
<A HREF="javascript:if(confirm('http://www.internic.net/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.internic.net/'" tppabs="http://www.internic.net/">http://www.internic.net/
</A></PRE>
</BLOCKQUOTE>
<P>
When a computer contacts your server, it leaves its IP address
as a calling card, which is recorded in the log file. The environmental
variable REMOTE _HOST also stores this address, or sometimes domain
name, as its value.
<P>
Having a record of your users' IP addresses can be used to determine
where your users are from, and to understand which servers you
are more popular on. This information can also be used to find
out the address and identy of any problem users. To find out the
information which comes with an IP address, consult the InterNIC
directory, whose URL was given earlier.
<H3><A NAME="TheReferURL">
The Refer URL</A></H3>
<P>
There is an environmental variable which records the URL of where
the user has come from as its value. The name of this environmental
variable is PREVIOUS_URL. This variable can be used to track a
user through a site, or to find out where your site connects to
the outside resources on the Web.
<H2><A NAME="TrackingHitswiththeLog"><FONT SIZE=5 COLOR=#FF0000>
Tracking Hits with the Log</FONT></A></H2>
<P>
The term <I>hits</I> is used very loosely on the Web, and means
everything from the actual action of picking any HTML link, to
the base unit used to measure Web site traffic. For the purposes
of this book a hit is simply any time a user calls up a resource
on the Web, whether it be an HTML document, image, or downloadable
program. When that resource is accessed successfully, a hit can
be considered to be counted against it, or on it. Moving about
within one HTML document would not be a hit, but moving from one
HTML document to another within the same site would count as one
hit.
<P>
To record a hit, one of the methods discussed in this chapter
can be used. The hit may be registered in different ways using
a short Perl snippet on the HTML document, or the hit information
can be read by a Perl script from one of the HTTP service's log
file.
<H2><A NAME="CountersRevisited"><FONT SIZE=5 COLOR=#FF0000>
Counters Revisited</FONT></A></H2>
<P>
Another way to keep track of Web site traffic is by creating your
own page counting scripts which do not rely on logs for statistical
information. The way in which this can be done is to use Perl
to create either a plain text file, or the more useful database
management file, or DBM file.
<P>
DBM files are used on the Internet so that different platforms
and different operating systems can access the same information.
With Windows NT DBM, files are accessed through an application
programming interface, or API. It is through the API that the
client communicates with the database. Microsoft's SQL server
may be used as an API. Manipulating DBM files with Perl is a straightforward
affair, as this next section demonstrates.
<H3><A NAME="ManagingDBMFiles">
Managing DBM Files</A></H3>
<P>
The main functions to use to manipulate DBM files in Perl are
"dbopen()," "dbclose()," "reset(),"
each()," "values()," "and keys()." Some
of these functions were dealt with earlier in the book, and the
others will be explained here.
<P>
To begin with, the dbopen command is used to create a link between
a DBM file and an associative array. The format for this would
be something like:
<BLOCKQUOTE>
<PRE>
dbopen(%new_array,DB_new_file, read-write-mode);
</PRE>
</BLOCKQUOTE>
<P>
where Perl will create two new files if the file name specified
in the statement does not exist. The new files would have the
names "db_newfile.dir" and "db_newfile.pag."
To prevent these files being created set the read/write mode to
"undef."
<P>
The different parameters specified in the above statement operate
like this: the %new_array is an associative array and behaves
like one; DB_new_file is the DBM file being opened, without specifying
either the ".dir" or ".pag" extentions(a full
path and file name for the DBM file should be used here); the
Read_write_mode which sets the file permissions for the DBM file.
<P>
To sever the connection between the DMB and the associative array
use the dbclose command in this format:
<BLOCKQUOTE>
<PRE>
dbclose(%new_array);
</PRE>
</BLOCKQUOTE>
<P>
There is just one small problem with this method of tracking a
Web site on an NT server. Currently, in Windows NT the DBM funtions
in Perl are unsupported. This method is included in this book
now for two important reasons: the first is as an example of how
tracking can be done outside of using logs, the second is that
the DBM function in Perl NT may be supported soon, so you'll be
ready for it.
<P>
To help deal with Perl scripts that use unsupported routines and
functions for Windows NT, a NT Perl checklist is necessary.
<H2><A NAME="NTPerlChecklistScript"><FONT SIZE=5 COLOR=#FF0000>
NT Perl Checklist Script</FONT></A></H2>
<P>
This section is a little out of place in this chapter, but it
seemed like a good idea to add it here. One big headache that
confronts Perl programmers, especially those working in non-UNIX
environments, is finding a Perl script that satisfies your needs,
but then when you try and run it it fails. After numerous futile
attempts at execution you discover that the script uses Perl functions
not supported in your version, or porting, of Perl.
<P>
In Windows NT, the list of unsupported functions is long enough
and extensive enough to cause problems with the inability to use
DBMs explained in this chapter. The following script is constructed
to search any Perl script for any currently unsupported NT functions.
Think of it as an acid test for new scripts you want to add to
your Perl library.
<BLOCKQUOTE>
<PRE>
#!/usr/bin/perl
# nttest.pl
# This is where the list of unsupported functions goes... @functions=("getnetbyname",
"getnetbyaddr","getnetent","getprotoent",
"getservent","sethostent","setnetent","setprotoent","setservent","endhostent",
"endnetent","endprotoent","endservent","socketpair,"msgctl","msgget","msgrcv",
"msgsnd","semctl","semget","semop","shmctl","shmget","shmread","shmwrite",
"ioctl","select($w, $x, $y, $z)","chmod","chroot","fcntl","flock","link",
"lstat","readlink","symlink","sysread","syswrite","umask","utime","crypt",
"getlogin","getpgrp","getppid","getpriority","getpwnam","getgrnam","getpwuid",
"getgrgid","getpwent","getgrent","setpwent","setgrent","endpwent","endgrent",
"setpgrp","fork","kill","pipe","setpriority","times","wait","waitpid","alarm",
"dbmclose","dbmopen","dump","syscall");
$filename=$ARGV[0];
if(!$filename) {
print "\nUsage: nttest.pl <scriptname>\n\n";
exit;
}
$linecount=0;
$errors=0;
open(SCRIPT, $filename);
while ($line=<SCRIPT>) {
$linecount++;
foreach $func (@functions) {
if ($line=~/$func[\s|(]/i) {
print "Line $linecount: Function $func() is unsupported
by Perl for Windows.\n";
$errors++;
}
}
}
close(TRACK);
if (!$errors) {
print "This script contains no unsupported functions, and should
work with Perl for Windows.\n\n";
}
else {
print "This script contains unsupported functions, and will not
work under Perl for Windows.\n\n";
}
</PRE>
</BLOCKQUOTE>
<P>
With this script you should save hours of time debugging a Perl
script that will never run on Windows NT. Now if someone could
write a Perl script that then fixed these unsupported features
so the script did work in NT, that would be really something.
Please remember that all is not lost. Most of these unsupported
functions are not useful in the scripts, and Perl is amazing at
doing the same task in different ways. With a little ingenuity
and reworking, these scripts may function fine in Windows NT.
<H2><A NAME="ChapterInReview"><FONT SIZE=5 COLOR=#FF0000>
Chapter In Review</FONT></A></H2>
<P>
In this chapter we covered the ability to keep track of a Web
site's traffic, using the example of the Goo Goo Records site.
Their site uses logs to generate reports to keep track of who
is using the site, which browser they are using, and where they
go in the site.
<HR>
<CENTER><P><A HREF="ch13.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/ch13.htm"><IMG SRC="PC.GIF" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/PC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A>
<A HREF="#CONTENTS"><IMG SRC="CC.GIF" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/CC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A>
<A HREF="contents.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/contents.htm"><IMG SRC="HB.GIF" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/HB.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A>
<A HREF="ch15.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/ch15.htm"><IMG SRC="NC.GIF" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/NC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A>
<HR WIDTH="100%"></P></CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -