CGI Scripts 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.*
If you have a custom CGI script that you need to use, simply upload it to your personal
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 (and NOT BINARY mode)
Those using Fetch should use Text mode (not Raw Data)
The first line of each script should read:
(please also see below)
One exception is if you are using PerlShop, it should read:
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.
<- if file resides in root
<- 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.
- 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:
- 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 Scriptalias 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:
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. Our built-in odometer counter is another example of this.
- 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.00404 = /usr/local/bin/perl
*Some newer servers will not have these earlier versions available.
In this case, use the default:
- 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"*
suexec and permissions:
- Our system does not use "cgiwrap" but suexec is available.
- New sites and all FrontPage'98 sites have suexec enabled by default. This will
affect the way cgi's are run on your site. It is more secure but requires the user to know
a bit more about permissions.
- Basically, a file executed from a web page with permissions of 755, owned by your
userid, has the associated group of bbsuser and is in a directory that has all these same
settings, will run under suexec and have access priveleges as if you were running it
yourself. This is an example directory listing:
- We have a central library of CGI's at /web/cgi-bin . Sites without suexec can use
the files there as is. A ScriptAlias points all URL references like this :
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. 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:
- 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
- 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
- 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.
echo Content-type: text/plain
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)
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 processing of CGI
arguments under TCL
- More information on CGI.
- 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
- a interesting page with many ideas on solving local searching problems.
- A great language to learn in the generation of dynamic documents (on-the-fly page
creation) such as forms.