What CGI scripts are

Normally when a Web browser looks up a URL the following happens. First your computer contacts the HTTP server with the URL. The HTTP server looks at the filename requested by your computer and then sends that file back. Your computer then displays the file in the appropriate format.

However, it is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back; instead it is executed as a program, and whatever that program outputs is sent back for your computer to display. This function is called the Common Gateway Interface or CGI. The programs are called CGI scripts. The directory that the CGI scripts sit in cannot be specified by you alone - you need the help of whoever runs your HTTP server.

In the School of Computer Studies here at Leeds it's Savio Pirondini and the rest of Support who run the HTTP server. When you ask Support to give you a Web page and a CGI directory they tell the HTTP server where to look for your Web files. For example, if your username is sam then your Web pages can be put in directory ~sam/WWW and your CGI scripts in directory ~sam/WWW/cgi-bin. When Support are told this they make sure that when someone sends URL

then the file ~sam/WWW/filename is sent back. And when they send the URL
then the file ~sam/WWW/cgi-bin/filename is executed. In all cases you have to set the permissions of the files and directories so that everyone can read them. You also have to set the permissions of all the directories and the CGI scripts so that they are executable by everyone.

In summary CGI scripts are programs which can generate and send back anything: sound, gifs/signs, HTML documents, and so on. In this tutorial we concentrate on generating and sending back HTML documents.

Start Next