Chapter 17

Chapter 17 - Teach Yourself Scheme in Fixnum Days [Go to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Teach Yourself Scheme in Fixnum Days [Go to first , previous , next page; contents ; index ] Chapter 17 CGI 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 [ 27 ] 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.scm on the server would be accessed as . The server runs the CGI script as the user nobody , who cannot be expected to have any PATH knowledge (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 "$@" implicitly assumes that there is a particular shell ( bash , say), and that there is a PATH , and that mzscheme is in it. For CGI scripts, we will need to be more expansive: #!/bin/sh ":";exec /usr/local/bin/mzscheme -r $0 "$@" 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 variables Here 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. (1 of 12) [2/6/2008 11:42:32 AM]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Teach Yourself Scheme in Fixnum Days CGI scripts talk back to whoever called them -- by giving them a new page. Note that the script first outputs the line content-type: text/plain followed by a blank line . This is standard ritual for a web server serving up a page. These two lines aren't part of what is actually displayed as the page. They are there to inform the browser that the page being sent is plain (ie, un-marked-up) text, so the browser can display it appropriately. If we were producing text marked up in HTML, the content-type would be text/html . The script testcgi.scm : #!/bin/sh ":";exec /usr/local/bin/mzscheme -r $0 "$@" ;Identify content-type as plain text. (display "content-type: text/plain") (newline)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 02/06/2008 for the course CS 4536 taught by Professor Fisler during the Winter '08 term at WPI.

Page1 / 12

Chapter 17 - Teach Yourself Scheme in Fixnum Days [Go to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online