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
start_form() methods. These methods both support the parameter
-target where you can specify a target frame for displaying the document or form.
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:
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:
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:
Microsoft Internet Explorer specifics can be found at this URL: