Search the Catalog
CGI Programming on the World Wide Web

CGI Programming on the World Wide Web

By Shishir Gundavaram
1st Edition March 1996

This book is out of print, but it has been made available online through the O'Reilly Open Books Project.

Previous Chapter 2
Input to the Common Gateway Interface

2.7 Other Languages on Macintosh Servers

The two commonly used HTTP servers for the Macintosh are WebSTAR and MacHTTP, both of which are nearly identical in their functionality. These servers use AppleEvents to communicate with external applications, such as CGI programs. The language of choice for CGI programming on the Macintosh is AppleScript.


Though AppleScript does not have very intuitive functions for pattern matching, there exist several CGI extensions, called osax (Open Scripting Architecture eXtended), that make CGI programming very easy. Here is a simple example of an AppleScript CGI:

set crlf to (ASCII character 13) & (ASCII character 10)
set http_header to "HTTP/1.0 200 OK" & crlf & -
         "Server: WebSTAR/1.0 ID/ACGI" & crlf & -
         "MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
on `event WWWsdoc' path_args -
   given `class kfor':http_search_args, `class post':post_args, `class meth':method,
         `class addr':client_address, `class user':username, `class pass':password, 
         `class frmu':from_user, `class svnm':server_name, `class svpt':server_port,
         `class scnm':script_name, `class ctyp':content_type, `class refr':referer,
         `class Agnt':user_agent, `class Kact':action, `class Kapt':action_path,
        `class Kcip':client_ip, `class Kfrq':full_request
   set virtual_document to http_header & -
       "<H1>Server Software</H1><BR><HR>" & crlf -
       "The server that is responding to your request is: " & server_name & crlf -
       "<BR>" & crlf
   return virtual_document
end `event WWW sdoc'

Although the mechanics of this code might look different from those of previous examples, this AppleScript program functions in exactly the same way. First, the HTTP header that we intend to output is stored in the http_header variable. Both MacHTTP and WebSTAR servers require CGI programs to output a complete header. Second, the on construct sets up a handler for the "sdoc" AppleEvent, which consists of all the "environment" information and form data. This event is sent to the CGI program by the server when the client issues a request. Finally, the header and other data are returned for display on the client.


Yes, Perl has also been ported to the Macintosh! This will allow you to develop your CGI applications in much the same way as you would under the UNIX operating system. However, you need to obtain the MacHTTP CGI Script Extension. This extension allows you to use the associative array %ENV to access the various environment variables in MacPerl.

Previous Home Next
Other Languages Under Microsoft Windows Book Index Examining Environment Variables

Back to: CGI Programming on the World Wide Web Home | O'Reilly Bookstores | How to Order | O'Reilly Contacts
International | About O'Reilly | Affiliated Companies | Privacy Policy

© 2001, O'Reilly & Associates, Inc.