Teach Yourself Scheme in Fixnum Days [Go to first, previous, next page; contents; index]Chapter 17CGI scripts(Warning:CGI scripts without appropriate safeguards can compromise your site's security. The scripts presented here are simple examples and are not assured to be secure for actual Web use.)CGI scripts  are scripts that reside on a web server and can be run by a client (browser). The client accesses a CGI script by its URL, just as they would a regular page. The server, recognizing that the URL requested is a CGI script, runs it. How the server recognizes certain URLs as scripts is up to the server administrator. For the purposes of this text, we will assume that they are stored in a distinguished directory called cgi-bin. Thus, the script testcgi.scmon the server www.foo.orgwould be accessed as http://www.foo.org/cgi-bin/testcgi.scm.The server runs the CGI script as the user nobody, who cannot be expected to have any PATHknowledge (which is highly subjective anyway). Therefore the introductory magic line for a CGI script written in Scheme needs to be a bit more explicit than the one we used for ordinary Scheme scripts. Eg, the line":";exec mzscheme -r $0 "[email protected]"implicitly assumes that there is a particular shell (bash, say), and that there is a PATH, and that mzschemeis in it. For CGI scripts, we will need to be more expansive:#!/bin/sh":";exec /usr/local/bin/mzscheme -r $0 "[email protected]"This gives fully qualified pathnames for the shell and the Scheme executable. The transfer of control from shell to Scheme proceeds as for regular scripts.17.1 Example: Displaying environment variablesHere is an example Scheme CGI script, testcgi.scm, that outputs the settings of some commonly used CGI environment variables. This information is returned as a new, freshly created, page to the browser. The returned page is simply whatever the CGI script writes to its standard output. This is how file:///C|/Documents%20and%20Settings/Linda%20Graue...es/Teach%20Yourself%20Scheme/t-y-scheme-Z-H-19.html (1 of 12) [2/6/2008 11:42:32 AM]
has intentionally blurred sections.
Sign up to view the full version.