FAQ's about CGI


Q. What is CGI ?

A. The Common Gateway Interface (CGI) is a standard for interfacing external applications with information servers, such as HTTP or Web servers. A plain HTML document that the Web daemon retrieves is static, which means it exists in a constant state: a text file that doesn't change. A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information.

For example, let's say that you wanted to "hook up" your Unix database to the World Wide Web, to allow people from all over the world to query it. Basically, you need to create a CGI program that the Web daemon will execute to transmit information to the database engine, and receive the results back again and display them to the client. This is an example of a gateway, and this is where CGI got its origins. Common functions perfromed by a CGI are Forms Processing, Animation, DataBase Access, etc.

The database example is a simple idea, but most of the time rather difficult to implement. There really is no limit as to what you can hook up to the Web. The only thing you need to remember is that whatever your CGI program does, it should not take too long to process. Otherwise, the user will just be staring at their browser waiting for something to happen.

Basically speaking, a CGI is a script or program written to handle functions that cannot be performed by plain old HTML tags.

Most CGI's are written as shell or PERL scripts, or C programs. Shell and PERL CGI's are commonly referred to as scripts because the commands are listed in a plain text file. CGI's written in C are commonly referred to as C programs, because the CGI must be percompiled into an executable program before it is used.


Q. What special needs to be done ?

A. You can create your own cgi directory. This directory MUST be named something other than "cgi-bin". It may be named "cgibin", "cgi", "scripts" or something else. This cgi directory needs to be in your 'www' directory with the permissions set of 755 (chmod a+rx). All the cgi scripts needs to end with the ".cgi" extension and also have the permissions set of 755. All cgi scripts need to start with: #!/usr/bin/perl


Q. What are the path names ?

A. In order for your script to work properly you must have the correct path for each variable. Users with virtual domain names should not use the standard name of 'cgi-bin' since this will conflict with the server's cgi-bin directory. These users should just name their cgi-bin directory to something else. In the below examples please use this rule of thumb:
(where 'u' = the first letter of your username and 'username' = your username on AIC)

$basedir = "/home/users/u/username/public_html/directory/";
This variable should contain the absolute system path to your directory. So if you keep all of your files in /home/users/u/username/public_html/ and you make a directory under there called 'directory', then $basedir would be set to: /home/users/u/username/public_html/directory/. The $basedir variable just saves you the time of having to type out the basedir over and over again for every file you want to include.

$basefile = "/home/users/u/username/public_html/images/";
This is the base filename where all of your images are kept. When the script chooses the images, the filenames from @files are appended to this to form a complete path to the image. Realize that this path must be an absolute path on the system and should not be relative to the WWW pages.

$baseurl = "http://www.accesscom.com/~username/directory/";
This is very similar to the basedir variable except that it will be used as a base reference to the files you want to search in terms of the web. So staying with the example above, if your main directory is called by: http://www.accesscom.com/~username/, the $baseurl would be set to: http://www.accesscom.com/~username/directory/

$cgiurl = "http://www.accesscom.com/~username/cgi-bin/script.cgi";
The url portion of the address to the script.cgi file. The file script.cgi needs to be placed in your cgi-bin and chmoded read/execute for users of your httpd. (chmod a+rx)

$date_command = "/bin/date";
This needs to be the path to your 'date' command.

@files = ("begin.gif","second.gif","third.gif","last.gif");
This is an array that includes all of the files you want to search. The directory paths and filenames should be in reference to $basedir. Wild cards are allowed in this array, so if joe wanted to search all html files in fun/ and work/, he would set his @files array up as: @files = ('fun/*.html','work/*.html'); You can also search whole directories at one time, like: @files = ('fun/','work/'); This would search all text files located in these directories. Putting exact filenames will search only that filename.

$mail
This option will allow you to be notified via an email address when a new entry arrives in your guestbook. The entry will be mailed to you as a notification. If you should choose to turn this variable on you will need to fill in the 2 variables that go along with it:

$recipient = 'username@accesscom.com';
Your email address, so that the mailing program will know who to mail the entry to.

$mailprog = '/usr/sbin/sendmail';
The location of your sendmail program on your host machine.

Perl5 = "/usr/bin/perl"
This is the default version of Perl running on both the shell server and the web server.

$title = "Home Page of Username";
This variable is used to display the title of your page in the search results and used to link back to your main page.

$title_url = 'http://www.accesscom.com/~username/';
This is the url to the html page you set up, so that it can be referenced from in the results page if users want to make another search.


Q. What CGI's are already available for my use ?

A.

Formmail - Formmail for your Web Site

Counter - Counter for your Web Site


Q. Where can I get different CGI scripts ?

A. There are a few sites on the internet that you can download different CGI scripts from. Here are a few that we most often:

Matt's Script Archive

ScriptSearch The Worlds Largest CGI Library

WebScripts (Perl CGI Scripts)

The CGI Collection

Dream Catchers CGI Scripts