W3U Customer Support

CGI Script Information

Contents:
General Information
More Technical Information
CGI Library
Server Side Includes
Trouble-shooting
Example Script
Links to Other Resources
Setting Permissions
Formmail, Message Board, Guestbook, Perlshop, Counter

General Information:

Our servers have the capability to run CGI scripts based on Perl, Unix SH, BASH, KSH, CSH, and C/C++ languages. Perl is a our language of choice for most applications as it is a world standard and is well suited to CGI. In addition, Perl code does not require manual compilations whereas C/C++ code must be compiled on our web servers prior to use.*

You can run your scripts from any directory (for Platinum accounts, we have created a cgibin directory for you.  You can also run scripts from that directory).  If you have a custom CGI script that you need to use, simply upload it to the server and set permissions to 755. Here are some helpful tips to follow when installing Perl scripts:

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

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

One exception is if you are using PerlShop, it should read:

#! /usr/local/bin/perl5.003
Reference the script using "cgibin", NOT using "cgi-bin"

Use ".cgi" extensions for all scripts

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

/web/guide/<domainname>/...
<- if file resides in root
/web/guide/<domainname>/cgibin/...
<- if file resides in cgibin

Substitute the path to the file beginning with your domain name. Your domain name is the directory name of your account.

Top

More Technical Information:

  • Scripts must be made executable with chmod 755 filename
    We have two FAQ's on file permissions in different styles,
    please choose the one appropriate for your level:

        Long Winded
        Really Long Winded

  • 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 permissions 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/local/bin/perl. This defaults to Perl version 5.00404*. Users of other versions of Perl 5 should use the path that applies to the version of Perl 5 that they are using. It will be one of the following:

                    /usr/local/bin/perl5.001
                    /usr/local/bin/perl5.002
                    /usr/local/bin/perl5.003
                    /usr/local/bin/perl5.00307
                    /usr/local/bin/perl5.00404   =  /usr/local/bin/perl

*Some newer servers will not have these earlier versions available. In this case, use the default:

        /usr/local/bin/perl

  • For users of the PerlShop script, the directory to use is /usr/local/bin/perl5.003*
  • For users of Perl 4: the directory for Perl 4 is /usr/bin/perl4.036* Perl4 scripts usually will need to have any @ or $ escaped with \ character to be perl 5 compatible. i.e., print "webmaster\@yourdomain.com"*

Top

CGI Library:

  • We have a central library of cgi's at /web/cgi-bin . Sites without suexec can use the files there as is. A Script Alias points all URL references like this :

             http://YOURDOMAIN.com/cgi-bin/
                   
    to our central library so you can use our cgi scripts and not have to make duplicate copies of the files.
  • Sites with suexec can not operate the cgi's in that library. You can copy any of them to your local cgibin directory and set the permissions as above.
  • 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.  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 .
  • See our tutorial for detailed information on SSI's

Trouble-shooting:

  • 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.
  • If you can't figure it out, ask us, we will help you by email on an "as time permits basis".
  • There are many undocumented examples in /web/cgi-bin and /web/cgi-src , however we don't support them until we document them and know they are working.

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_REFERER
echo You are using $HTTP_USER_AGENT as a browser.
echo $HTTP_USER_AGENT >> agentfile.txt
echo \<a 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)

Top


Formmail, Message Board, Guestbook, Perlshop, Counter

Your web hosting account comes with a variety of cgi scripted features.  Each feature, comes with comprehensive set up instructions, which can be downloaded from your web server.

Top

CGI Links:

Matt Wright's CGI Script Archive: Lots of good scripts and links to other info on CGI.

The CGI Resource Index.  Over 1000 related CGI resources.

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

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.

FeLIpe's Applescript CGI Examples
- An Apple reference to CGI-Scripting with examples. We're not Mac-users at W3U, so I haven't tested this site out. Mac people, let us know what you think.

Imagemap Help Page
- Imagemapping 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.

Top