NetNation Managed Hosting, Server Colocation Services and Shared Web Solutions
Customer Login Webmail Click for Canadian Site
 
Domain Name Registration
  spacermore extensions
 

CGI Scripting FAQ



What are forms and CGI's?
Why isn't my CGI script working? (Binary, ASCII & Permissons)
How do I implement custom scripts?
Where do I put my CGI scripts?
How do I use feedback forms with the NetNation mailer?
What are environment variables?

What are forms and CGI's?
Forms are blank fields (input boxes, check boxes, radio buttons) on a page that allows browsers to make their selections. To process these selections, the forms need to be submitted and parsed by programs on the server. CGI stands for Common Gateway Interface. It is a set of rules (or protocols) that sets the basic definitions of how a program should parse these submitted forms.

Why isn't my CGI script working? (Binary, ASCII & Permissons)
Here are some common problems encountered with CGI scripts:
  • Your script was uploaded in BINARY mode instead of ASCII mode.
    Re-upload the file in ASCII transfer mode in your FTP program. This means the script must actually upload as a 'text' file. If your FTP program automatically puts a ".txt" notation at the end of the script, then simply delete the ".txt" from the file name after you upload it to the server.
  • The directory your CGI or Perl script lives in is not set to the proper permissions. You do not have the directory permissions set to 755.
    ( chmod 755 cgi )
  • CGI's must have permissions of "755" or they will not execute.
    ( chmod 755 *.cgi )
How do I implement custom scripts?
Our servers have the capability to run CGI scripts based on Perl, Unix SH, KSH, CSH, and C/C++ languages. Perl is our language of choice 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 cgi directory. Here are some helpful tips to follow when installing Perl scripts:
  • Upload to your cgi directory and ensure proper file permission settings
  • Upload in ASCII transfer mode (NOT BINARY mode)
  • The first line of each script must read: #!/usr/bin/perl
  • Reference the script using /cgi (NOT /cgi-bin)
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/<userid>/HTML/... <- if the file is in your web site root directory
/home/<userid>/HTML/cgi/... <- if the file is in your cgi directory
Substitute the path to the file beginning with your userID. Your userID is the directory name of your account.


Where do I put my CGI scripts?
Place your CGI scripts (or programs) in your HTML/cgi/ directory. The scripts must have the .cgi extension. We can allow scripts to run in alternate locations. Please contact NetNation Support for any special requests. For example, if you had placed a cgi script called surprise.cgi in the directory HTML/cgi/, you access it via: http://www.your_domain.com/cgi/surprise.cgi

How do I use feedback forms with the NetNation mailer?
If you already have an email form, you can use our mailer. To access it, you need at least these lines in the <FORM...> tag of your .phpl file.

<FORM ACTION="/cgi-bin/mail.vws?nickname" METHOD="POST">
Name: <INPUT NAME="from-name" SIZE=30>
Email: <INPUT NAME="from-email" SIZE=30>
Subject: <INPUT NAME="subject" SIZE=30>

<B>Message</B>
<TEXTAREA NAME="message" ROWS=10 COLS=50>
</TEXTAREA>
<INPUT TYPE="submit" VALUE="Send Form">
<INPUT TYPE="reset" VALUE="Reset Form">
</FORM>

Probably the easiest way to build your own email form is to copy and paste the tags above, then add any other information you need from the form.

It's not essential that the tags be visible to the person browsing your site. If you don't want a particular field to be visible to the browser, but want it to be mailed to you with the rest of the form information, use the TYPE=HIDDEN tag modifier.

The mail.vws script will take the NAME="from-name" and NAME="from-email" input and add them to the email headers, thus you need to call the Name: and Email: fields as "from-name" and "from-email" respectively.

Note: nickname is defined in your /home/login-name/HTML/mail.list file (ie. $DOCUMENT_ROOT See: What are environment variables?) in this format:

nickname:email_address@somedomain.com
.
nickname99:another_address@somedomain.com

Example: support:support@netnation.com
sales:sales@netnation.com
somebody:somebody@sway.com

Additional Options
1. NAME="next-url" - when the form is submitted, this tag will direct browsers to the URL (webpage) specified instead of the default (somewhat ugly) Message Sent page.
ie: <INPUT TYPE=HIDDEN NAME="next-url" VALUE="http://yourdomain.com/thankyou.phpl">

2. NAME="previous-url" - adding this tag will generate a link to the specified URL on the Message Sent page. While this can really point anywhere, it's usually pointed to the previous page.
ie: <INPUT TYPE=HIDDEN NAME="previous-url" VALUE="http://yourdomain.com/somefile.phpl">

3. NAME="ignore:values" - adding "ignore:" to a tagname prevents that INPUT from being printed out or sent with the email.
ie: To prevent the "subject" from being printed out: <INPUT TYPE=TEXT NAME="ignore:subject">

4. NAME="require:values" - adding "require:" to a tagname will make filling that field required. An error message will be returned to the browser if the field isn't entered. This is particularly useful for ensuring you get the email address of a form poster.
ie: To accept a form only when the email address has been filled: Email: <INPUT TYPE=TEXT NAME="require:from-email">

You can combine "require:" and "ignore:", ie: NAME="require:ignore:value"

What are environment variables?
Environment variables are used when you write CGI, and they inform the web server where your web site files are located, along with other information about the status of the web site, browsers and log files.

An important variable is $DOCUMENT_ROOT. This variable tells the web server where the top most directory of your site is located. Your site will not work without this variable.

To list your site's environment variables, access the stock CGI called printenv in the cgi-bin directory. ie: http://www.yourdomain.com/cgi-bin/printenv