CGI: An Introduction
CGI is not actually a programming language- the three letters stand for Common Gateway Interface. That doesn't seem like much help. Basically, CGI allows you to use a program behind the scenes to perform tasks that cannot be done through HTML. For instance, many Web sites use graphical counters to display the number of times the page has been viewed. In order to keep track of that number, you will need a way to add one to the number each time the page is loaded. HTML doesn't have this ability- it is only a markup language. To accomplish this, you need to use a programming language that will allow you to write a program to store and increment the number. The most commonly used languages for this purpose are Perl and C/C++, which allow you many more options than using plain HTML.
What You NeedTo use CGI programs, you will need to find out a little about your Web server. Some free Web hosting services do not allow you to use your own CGI programs, and do not give you a CGI directory. However, if all you need is a e-mail form results, or some other common scripts, you can find a number of services that will run the program from their server, allowing you to post HTML code that calls their program.
If your Web server allows you to use your own CGI programs, you are almost ready to roll. Now you are left with a few of options:1. Should I write my own CGI programs in Perl, C\C++, or another language?
2. Should I try another solution such as ASP or PHP?
3.Should I use freeware or commercial CGI programs written by others?
If you choose the first option, you will need to learn Perl or another language that will through the Common Gateway Interface. There are some introductory Perl tutorials on this site. You may also want to buy a book on Perl.
Option two is quite popular as well. You will need to learn a little about the language you wish to use and your Web host will need to be set up to use the language you choose.
Option three is an easy way to use a script on your own server. There are plenty of free scripts available on the Web, so that you do not have to pull your hair attempting to learn a programming language.
Installation of a ScriptAs far as installation goes, alot depends on your server- such as what directory they will allow you to place your CGI programs in, the type of server (Unix, Windows NT, etc.), and the absolute path to that directory. An absolute path is something you can usually see using your FTP program. In your location box, you should see something like this:
This is an absolute path to a CGI directory. You may also need the absolute path to a file. If you need the absolute path to your main page, it may look something like this:
However, this is different from server to server. You will need to use absolute paths to set some of your variables in the scripts. If you are unsure, try the FTP program or ask your Web host about the absolute path.
Further ReadingNewbie's CGI Installation FAQ
An article by Boris Mordkovich explaining the basics of installing a CGI script.
CHMOD & File Permissions
Some helpful hints on what the file permissions set by the chmod command mean.
Beginning Perl Tutorials
A set of tutorials to help you get started on programming your own CGI scripts using Perl.