CGI and Perl

Netscape Cookies and Other Netscape Feature Tags

Netscape Navigator 1.1 and later support a feature called cookies. Cookies provide the capability to maintain session information on the client end. Cookies are essentially little bits of information that are stored on the client's local disk and then may be obtained by a CGI program for future use. Cookies provide a better way to store persistent session information for individual clients. Server maintained files can become unruly as more clients are managed. It makes sense that client-specific information be stored at the client. There is a function in the CGI.pm module that provides a simple callable interface for access to these cookies.

The way to create a cookie is by using the cookie() method and then passing the cookie created by that method to the header() method to be incorporated into the document header. You can then access the cookie by just passing the -name argument without the -value argument. Here is an example of how to create a cookie as part of your document:

$cookie=$q->cookie(-name=>`Userid',-value=>`bdeng',-expires=>"+1h",
                   -path=>"/cgi-bin");
 print $q->header(-cookie=>$cookie);

This creates a cookie called Userid, which is set to bdeng and expires one hour from the time it is created. This cookie will also be valid only for documents that begin with the partial path of
/cgi-bin. Later, when a program in the /cgi-bin path is called, it can query the value of the Userid cookie by calling the cookie method with -name=>`Userid'. At the time of this writing, this capability existed only in the CGI.pm module and not in the CGI modules contained within the LWP modules.

Another feature of Netscape that other browsers are beginning to adopt is that of frames. You can create a page with multiple frames where each frame refers to a separate URL. You can then target these frames with links from the other frames. This provides the user with a nice uniform way of navigating through a site without having to jump all over the place. Frame support is also available in the CGI.pm module as part of the header() and start_form() methods. These methods both support the parameter -target where you can specify a target frame for displaying the document or form.

Summary

This chapter touched on some of the more advanced issues surrounding CGI programming and HTML markup. If you are interested in learning more about the CGI specification and what it is capable of, a good starting point would be the NCSA Web site at the following URL: http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

The most important issue you will probably face with respect to CGI programming is that of maintaining a persistent state across transactions. The examples provided in this chapter should help you in understanding solutions to that problem.

The best reference for the evolving HTML specification is at the W3C Web site at the following URL: http://www.w3.org/pub/WWW/MarkUp/MarkUp.html

You might also like to keep up to date with the specific features provided by Netscape Navigator and Microsoft Internet Explorer. Netscape Navigator specifics can be found at the following URL: http://developer.netscape.com/library/documentation/htmlguide/index.htm

Microsoft Internet Explorer specifics can be found at this URL: http://www.microsoft.com/intdev/prog-gen/webpage.htm

by BrainBellupdated
Advertisement: