THRIFTWEB.com

Reliable Hosting from just $4.95/month!


 
THRIFTWEB SUPPORT CENTER:
Chapter Three - CGI Scripts


CHAPTER THREE - CGI Scripts

CGI (Common Gateway Interface) is a standard for running external programs from a Web server. CGI allows the returned HTML page to be dynamic - for example, with a CGI script you could access information in a database and format the results as part of an HTML page. If you're going to create web pages, then at some point you'll want to add a counter, a form to let visitors send you mail or place an order, or something similar. CGI enables you to do that and much more. From mail-forms and counter programs, to the most complex database scripts that generate entire websites on-the-fly, CGI programs deliver a broad spectrum of content on the web today. Not surprisingly, CGI scripts are very popular and used extensively throughout the World Wide Web. A CGI can be written in any programming language, but Perl is the most popular.

There are a number of very good introduction to CGI documents available on the Web. The information given below is a summary of the most important points to remember when using CGI. Please refer to the following for a more in-depth introduction:

Key points to bear in mind when using CGI scripts:

  • The pre installed scripts available through CPanel are the easiest to use, but if a certain script does not do exactly what you want, feel free to look for better scripts on the Web. You can usually find a script to do almost anything, especially if you are prepared to pay.

  • Read all available documentation on a particular script before using it. This will help avoid most problems.

  • CHMOD ("Change Mode") means change the permissions on a particular file (usually the script itself). The CPanel File Manager allows you to quickly do this, as do most FTP tools.

  • Important - after uploading cgi-bin scripts, CHMOD to 755 (unless the script documentation specifically states otherwise). For example, you need to CHMOD the pre-installed CPanelCGI EMail scripts to 755 to use them properly.

  • Many scripts need to know the path to Perl (scripting language engine) and to sendmail (HTTP mail engine). You can find this information on the front page of CPanel.

  • Make sure you test your scripts repeatedly! Testing is vital to make sure everything is working to your satisfaction.

CGI is the method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. Why learn CGI?



How do I run my own CGI programs?

Put your CGI programs in the cgi-bin directory.
  • The cgi-bin should automatically change the permissions to chmod 755 for you

A special note - this does not apply to frontpage webs, follow normal cgi instructions

The location of preinstalled scripts is /cgi-sys.




How do I use cgiemail, and Formmail ?


CGIemail:This is a program that will email you the forms filled out from the web.


Please use formmail.pl while we rewrite the section on CGIemail.

Formmail is a very easy to use form processor, simply place the following on any page after entering your domain.

<FORM METHOD=POST ACTION="http://yourdomain.com/cgi-sys/FormMail.pl">
<input type=hidden name="recipient" value="sales@yourdomain.com">
<input type=hidden name="subject" value="Order">
<input type=hidden name="return_link_url" value="http://yourdomain.com/">
<input type=hidden name="return_link_title" value="Back to Main Page">

Be sure to replace yourdomain, with your real domain name.

Other CGI Questions:

"Where do I put my cgi-bin scripts?"

 Put them in the subdirectory cgi-bin which should be under your public_html directory. You may then call them thru a browser as http://www.yourdomain.com/cgi-bin/your.cgi

 "I don't have a cgi-bin directory!"

 Make it by typing mkdir cgi-bin while in your public_html directory.

 "How do I access cgi-bin scripts in the cgi-bin directory?"

 If your domain name is bart.com, and the script itself is called your.cgi, access them as http://www.bart.com/cgi-bin/your.cgi.

 "Hey! /cgi-bin/ doesn't work for me!"

 Ask us to activate your cgi-bin directory.

"I am getting the message 'POST not implemented'. Help!"

 You probably are using the wrong reference for cgiemail.

Another possibility is that you are pointing to a cgi-bin script that you have not put in your cgi-bin directory.

In general this message really means that the web server is not recognizing the cgi-bin script you are calling as a program, it thinks it is a regular text file.

Additional CGI EMail Info:

CGI EMail is a simple, easy-to-use script that takes the results of any form and sends them to you via e-mail. Because it is already installed, minimal configuration is required to successfully use the script.

The following steps provide quick summarized instructions for CGI EMail. Be sure to read the CGI user guide for detailed instructions on using CGI EMail.

To configure CGI EMail:

  1. Create an HTML form with a number of named input fields. Refer to this page for more detailed information of the action component of the form.

  2. Create an e-mail template (a .txt file) that displays the format in which you want your form information displayed in the e-mail. Make sure all your form name codes are one word and in square brackets [].

  3. Upload the .txt and form files to your site.

  4. Go to your cgi-bin directory and change the file permissions on cgiecho and cgie-mail to 755.

  5. Test the script. The cgiecho script is designed for testing online, so you do not have to wait for e-mail to be sent or received.