Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Then, set up the header and titles for an HTML document in the program just after reading all of the files in the log directory into the list:

   # Get the list of log files into an array.

       @LogFiles = readdir (LOGD);

   # Crank up a Web page.

       HTML_Header ($Title);
       print "<BODY>\n";
       print "<H1 ALIGN=\"CENTER\">$Title</H1>\n";
       print "<HR>\n";

Last, the portion of the script that prints the data needs a near-total rewrite:

  i f ($LogFile =~ /(..)(..)(..)(..)/)
       {
       $year = $2;
       $month = $3;
       $day = $4;
       }

   print "<H3>Date:    $month/$day/$year:</H3>\n<HR>\n";
   print "<TABLE WIDTH=50%>\n";
   for ($n = 0; $n < $HitCount; $n++)
       {
       print "<TR>\n<TD>$IPHits[$n]</TD> <TD>$NumHits[$n]
   accesses</TD>\n";
       print "</TR>\n";
       }

   print "</TABLE>\n<HR>\n";

Notice that the print statements format the data in HTML tables. They look better that way.

Make these changes, then save the file as webhit.pl in a directory accessible to your Web server through CGI. Then invoke it as a URL from your Web browser. You’ll see something similar to what is illustrated in Figure 9.9.


Figure 9.9:  The hit counter moves to the World Wide Web.

Congratulations! You’ve moved your hit counter to the World Wide Web.


EXERCISE:  The Sambar Server: Building Your Web Site

As you’ve learned in this skill, there isn’t a whole lot of work involved in switching between the IIS format of Web server logs and the Sambar format. In fact, modifying the code presented in this skill to accommodate the Sambar server is easier than for IIS, because Sambar keeps all of its server logs in one file.

You can configure the size of the file through the server’s administrative functions. When it reaches its maximum size, it will begin writing over itself.

Surely, your imagination has been piqued by some of the statistical concepts in this skill. Why don’t you apply that imagination to some of these exercises:

  The date/time format in the Sambar logs is slightly different than that of IIS. Use the date-formatting code in webhit.pl as a starting point in your own code snippet to take a log entry’s date and time apart and store them in separate variables.
  Sometimes, you won’t want to display all of the entries from the log. Design an HTML form that will allow you to enter a range of dates. The URL invoked by the form’s Submit button will be your Perl-CGI program that will decode the dates sent to you and pull up entries that fall within the range submitted.
  Design a hit-counter program that can analyze the range of times that a particular client was connecting

Moving On

You’ve undertaken a lot in this skill. You have built, from the ground up, the capability to analyze your Web server logs in a simple fashion. You have built a foundation for a full statistical analysis of your Web site.

In Skill 10, you will learn about HTML in detail: how it was derived from the Standard Generalized Markup language, some examples of full-blown SGML, and how the “parent” led to the “child” as the lingua franca of the World Wide Web. You’ll also learn how modern-day HTML interacts with the Web.

Are You Experienced?

Now you can…

  find, open, and decode the Web server log files for your server
  write a program to split each log entry into its individual fields and display them
  count the number of connections to your site from individual clients on the Web
  format your analyzed data in HTML and write it out to a Web page


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.