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


Getting around HTML

The quick and dirty way around this limitation would be to change the name of your Web site from, say, www.MySite.com to www.MySite.com/scripts/access.pl.

That’s ugly. You don’t want to do that.

Some Webmasters point their site URLs to an HTML document that is just a facing page, which puts up a “Welcome!” message and advises the visitor to click on a hyperlink to enter the site. Figure 4.6 is an example of a facing page. The “Click here to enter!” message is the hyperlink.


Figure 4.6:  A Web site facing page with a hyperlink to the real thing

The hyperlink is a URL to a Perl script that runs the access counter and also draws the entire home page. This is not a bad solution, though it requires a somewhat inelegant extra step.

Sadly, the only other solutions are based on proprietary extensions to HTML or equally proprietary graphics packages. This is such a perplexing problem that a small industry has sprung up around it—you can actually rent space on Web sites that do nothing more than keep track of your visitors and draw the count on your home page!

You will learn about some of the HTML extensions and a graphics package that can do the job in Skill 8. However, one extension, frames, is interesting enough to discuss here.

Using Frames to Automate a URL

A few versions back, Netscape developers came up with the idea of including frames in the HTML that their Navigator browser would understand. This gave the browser, and the HTML developer writing Web pages for Navigator, the ability to break a Web page up into different “windows,” each operating independently of the others. At the time, it only worked with Netscape’s software, which is why you still see a lot of Web pages that give you a choice between “frame-capable” displays and regular HTML.

Microsoft included the ability to recognize and deal with frames in its Internet Explorer browser, so the two most popular Web packages on the market today will do frames. As a result, it is not absolutely imperative to make provisions for “frame-damaged” browsers any more, which definitely was not the case even a couple of years ago. These days, the chances are extremely good that you can depend on your visitors having the capability to display frames.

Figure 4.7 illustrates a home page constructed with frames.


Figure 4.7:  This is a Web page that uses Netscape frames.

Interestingly, Figure 4.7 also illustrates a home page with a built-in access counter. Its creator used a feature of the frame extensions that Netscape tacked on to HTML.

On a frame-capable Web site, you generally make the home-page HTML document the one that sets up the frames. It then calls in the actual HTML documents that comprise the home page. The beauty of this setup, for our purposes, is that each frame declaration needs to know what HTML document it should call in, but the declaration effectively is in the form of a URL. The result is that you can put any valid URL in a frame declaration, including the path to a Perl script that will generate a number showing the “hits” on the Web site and draw the home page for you.

Figure 4.8 shows the HTML document that draws the page in Figure 4.7. Notice that the source for the frame named Main, which is the window on the right in Figure 4.7, is a URL pointing to access.pl. The remaining information is a list of arguments to access.pl. It specifies the HTML document to draw as the home page and the location of the file in which the access count is stored.


Figure 4.8:  This HTML code produces the Web page shown in Figure 4.7.


TIP:  Rather than generating HTML documents directly through strings that are printed out to the Web server, it is cleaner to make your Perl program read and print each line of an actual HTML file. This keeps the two types of code separate and it’s quite a bit easier to maintain. You’ll learn more about this in Skill 5.


EXERCISE:  The Sambar Server: Building Your Web Site

You created an access counter in this skill and learned enough about Perl and CGI to drop it into your own home page on the Sambar server.

  Save your original home page and make another that uses frames. Point the main page to a URL that refers to your Perl program to print the access count (in addition to the rest of the page).
  Search through the World Wide Web for other Web sites that have access counters in them. How many show the count as a graphical image? In Skill 8, you'll learn how to do this for your own Web site.

Moving On

HTML forms are the most heavily used interactive construct on the World Wide Web. In the next skill, you’ll learn how to gather and process information sent to you through CGI from a form.

Are You Experienced?

Now you can …

  write a Perl script to count the number of visitors to your Web site
  differentiate between real visitors and simple test visits to your site
  make decisions in your Perl programs with the if statement
  write an HTML document that will run your Perl access counter automatically


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.