11.01 Brief Introduction to CGI

What is CGI?

CGI is the Common Gateway Interface, which is essentially a standard interface between different processes normally running under a web server such as Apache, IIS or Abyss.

CGI is not a language. It is a protocol. It can be used to communicate between Web forms and your program. A CGI script can be written in any language that can read STDIN, write to STDOUT, and read environment variables. This applies to almost any programming language, including LynPlex.

Structure of a CGI Script

Here's the typical sequence of steps for a CGI script:

  1. Read the user's form input from STDIN.
  2. Do what you want with the data.
  3. Write the response (usually HTML) to STDOUT.

LynPlex and CGI

If the first two characters of a LynPlex script are a Unix shebang (#!) the script is treated as CGI and all output is sent direct to STDOUT without any formatting taking place.

The following notes assume that you are familiar with LynPlex and that CGI scripts are being placed in the cgi-bin folder on your server.

See apache for information on how to set up an Apache server to run LynPlex from another folder.

Creating a Simple Web Page

As most programming examples start off with a program to display “Hello World”. We shall therefore so the same.

First create the code to write a simple web page to STDOUT.

put "Content-type: text/html"
put "<html>"
put "<body>"
put "<h1>Hello, world.</h1>"
put "</body>"
put "</html>"

Store the script on your server and call it from a web browser.

You have written your first CGI script using LynPlex.

lynplex/lp1101.txt · Last modified: 2012/09/08 11:48 (external edit)