Contents:
General Information
More Technical Information
CGI Library
Server Side Includes
Troubleshooting
Example Script
Links to Other Resources


General Information:
Each server has the capability to run CGI scripts based on PHP, Perl, Unix SH, BASH, CSH, and C/C++ languages. Perl and PHP are a our languages of choice for most applications as it is a world standard and is well suited to Internet activities. In addition, Perl and PHP code does not require manual compilations whereas C/C++ code must be compiled on our web servers prior to use.*

In most cases, you will not need to upload a script. Our servers have a library of commonly called scripts such as cgiemail, webform, etc. If you have a custom CGI script that you plan to use, simply upload it to your personal "cgibin". Here are some helpful tips to follow when installing Perl scripts:

Utilize any directory except "cgi-bin" for your own scripts. We recommend placing them in your cgibin directory to help consolidate them.

Upload in ASCII transfer mode (NOT BINARY mode) Those using Fetch should use Text mode (not Raw Data)

The first line of each script should read: #! /usr/bin/perl (please also see below)

Reference the script using "cgi-bin", NOT using "cgibin" (though note that the actual directory that you place the scripts into is "cgibin") as this is references a different directory altogether.

Use ".cgi" extensions for all scripts, not ".pl" as the system is setup to recognize a ".cgi" as any one of these.

If a script calls another file within your account, but the script does NOT require a URL, you need to use the system path.

/home/<username>/<domainname>/www/... ---> the url to reference a page in this directory is http://www.domainname/file.htm

/home/<username>/<domainname>/cgibin/... ---> the url to reference a program in this directory is http://www.domainname/cgi-bin/file.cgi


Substitute the path to the file beginning with your domain name. Your domain name is the directory name of your account.
More Technical Information:
  • Scripts must be made executable with chmod 755 filename. The should be placed in the cgi-bin which includes security measures.
  • Filenames that end with the .cgi extension can be placed anywhere in your site but we recommend placing them in your local cgibin directory to consolidate them. If you need to use a different extension, we can create a script alias for your local cgibin directory (default on new sites) so that any file there will execute (provided perms are set).
  • The path to "sendmail" on our system is /usr/sbin/sendmail
  • Scripts that are to respond to the calling browser with a complete HTML page must have the Content Type tag as the first line of output:

              print "Content-type: text/html\n\n";

    Otherwise, they must be named with the nph- prefix. The nph- stands for non-parsed-headers. For example, let's say date.cgi returns the date as an SSI. So date.cgi becomes nph-date.cgi so it doesn't mess up the rest of the page.
  • Perl scripts will REFUSE to run if uploaded in "binary" or "raw data" mode from a non-UNIX computer. Be sure to set your FTP software to "ascii". Mac users should choose "text" mode.
  • For users of Perl 5: the default directory for Perl 5 is at /usr/bin/perl. This defaults to Perl version 5.005_03

            /usr/bin/perl

CGI Library:
  • We have a central library of cgi's at /web/cgi-bin . A script alias points all URL references like this :

             http://YOURDOMAIN.com/cgibin/
                   
    to our central library so you can use our cgi scripts and not have to make duplicate copies of the files.
  • You can use any directory other than cgi-bin or icons to store your scripts but we recommend using your cgibin (no hyphen) directory so we can find them if you need help.
Server Side Includes:
  • <!-- Server Side includes --> only work in files with the .shtml extension. The cgi file must have its execute and read public bits on to be run from a browser. The file that contains the include only needs to be readable. Try these commands:

           
            chmod 755 file.cgi

            chmod 644 file.shtml

  • While you can use a .htaccess file to have the server parse all .htm or .html pages in a directory (and its sub-directories), this will slow the server as it will be parsing some files that do not have SSI's in them. We recommend being very selective if you use this technique. The contents of the .htaccess file would be:

            AddType text/x-server-parsed-html .htm .html


  • You can name your home page index.shtml to use PARSE(Server Side includes) within it or index.cgi to use a script that creates the home page on the fly. Using an index.cgi to read incoming request headers for browser-type is a good use for this technique. If your index.cgi serves pages based on the HTTP_HOST variable, it may be in violation of our parked domain policy. We recommend checking with Tech Support if you are not sure.
  • <!--#exec cgi="mycgi.cgi" --> is a cool way to output the result of a simple cgi script into the middle of somefile.shtml .
  • More detailed information on SSI's can be found at:

Troubleshooting:
  • If you can't figure out why it doesn't work, run it from the command line via telnet, or rename it to nph-Scriptname. You'll see more error messages. Running it with the perl w flag will give even more error messages:

            perl -w   file.cgi

  • The three most common cause for errors are permissions, permissions and permissions.
  • CGI is programming, don't be mistaken into thinking it is as easy as HTML. It isn't.
  • If you are going to use perl, buy a Perl book, please.
Example of a CGI Script: "myfirst.cgi"
#!/bin/sh
echo Content-type: text/plain
echo
echo 10 print "HELLO"
echo 20 goto 10
echo Hello there I see you saw my page at $HTTP_REFERRER
echo You are using $HTTP_USER_AGENT as a browser.
echo $HTTP_USER_AGENT >> agentfile.txt
echo \&lta href=\"http://mydomain.com\"\> Home \</a\>

Yawn - Notice the \ escapes, the blank echo after the content-type line. Also If you want to use agentfile.txt line, I had to upload a blank file called agentfile.txt, and then use the file manager to set PUBLIC WRITE on that file. Or the script will not work! (telnet: touch agentfile.txt;chmod o+w agentfile.txt)

CGI Links:

Galaxy's CGI- Common Gateway Interface
- Lots of information on CGI scripting, and the longest URL on the Web, including pointers for more information on image mapping, etc.

Julia Martinson's Collection
- a great collection of information on CGI & HTML.

O'Reilly & Associates
- Don't normally recommend books, but in the case of Perl, UNIX, Linux, Scripting, etc. your might need to read-up with the best.

The Common Gateway Interface
- An introduction (with examples) to CGI scripting. One of the best sites.

Shareware CGI Scripts
- Consists of scripts for Guest Book, Forms, and Counters. Includes some Apple programs as well.

CERN HTTPD
- Resources for image-mapping, scripts, forms, search engines, CGI, etc. Please note that this is not our server, though similar, and some of the steps (BIN references) are different. Please refer to our FAQ for specifics on this.

Accessory Scripts- CERN
- Reference for forms submissions, etc. Again, the references are going to be slightly different for our server and please refer to our FAQ documentation for the changes needed.

The processing of CGI arguments under TCL
- More information on CGI.

Accessory Scripts- CERN
- Reference for forms submissions, etc. Again, the references are going to be slightly different for our server and please refer to our FAQ documentation for the changes needed.

Imagemap Help Page
- Imagemaping made simple in an easy to follow guide.

HTGREP
- if you need a searchable index, this is supposed to do the trick. I haven't messed with it yet, though.

NASA's 'Information on Search Tools'
- a interesting page with many ideas on solving local searching problems.

PERL
- A great language to learn in the generation of dynamic documents (on-the-fly page creation) such as forms.


 

OfficeOnWeb
261 Hines Road
Polk. PA 16342
Main Phone: 301-327-7500
FAX (call for number)
Toll free is available for clients only (call for number)
Copyright © 1993-2005 by Office on Web of Evergreen Colorado