Adding CGI Scripts

A CGI script works by taking input from your Web page and sending that input to an external program for processing. Usually, it returns a new Web page that has the results of that processing on it. The input is most often data from a form, but it can sometimes be just a link that a user clicks to activate the program.

Basic techniques

Before you do anything, you have to get the script. Whenever I describe a script in this book, I provide you with the URL of the site from which you can download the script. After you have the script, follow these basic steps to use it:

1.
Read the instructions for the script. Let me say that again: Read the instructions.

After you’ve worked with a few scripts, it’s tempting to just plunge right ahead without looking. After all, most scripts plug in pretty much the same way, and you can often get away with skipping the instructions. That’s the cause of about 812 percent of the problems that people have with scripts, though. All it takes is to misunderstand or misinterpret one little setting, and the whole script won’t work.

The instructions are often in the standard ReadMe.txt file. Sometimes, the script doesn’t have a ReadMe file, though, and the instructions are embedded in the text of the script itself in the form of comments. (Comments are notes the programmer adds to provide information, and they’re marked so that they’re differentiated from the program code and don’t interfere with the running of the program.)

2.
Open the script file in a text editor and make any necessary changes so that it works with your particular setup. After you do this, save the modified script.

You may, for example, need to add a list of URLs for a link menu, an e-mail address to send a message to, or the location of your site’s main Web page. You don’t need to understand the programming in order to do this. Just follow the instructions and replace the sample values in the script with your own values.

If you use a word processor to make the changes, make sure that the script gets saved as plain text and that the original file extension doesn’t get changed either. You don’t want a bunch of word processing formatting codes embedded in the script!

3.
Add the HTML code that the script’s instructions say to add to your Web page.

As with the script, you probably need to change a few sample values to the actual values. The HTML code is usually nothing more than the location of the CGI program, entered as the action attribute of a form.

4.
Upload the script and the modified HTML file to your Web server.

The HTML file goes in the normal HTML folder, and the script goes into the cgi-bin folder.

Solving problems

The basic techniques described in the preceding section work in almost all cases, but in some situations, you may need to modify the script a bit more to get everything working just right.

For example, nearly every script you find assumes your cgi-bin directory is called cgi-bin. Yours may be simply named cgi, for example. If that’s the case, you need to change the typical folder references in the script to match your folder name.

You may also find that the standard file extensions, like .pl for Perl files, aren’t allowed in your CGI setup. In that case, you have to change the file extension to whatever your server demands. A file named search.pl, for example, may need to be renamed search.cgi.

If you try to run the script and nothing happens, here are some troubleshooting options:

Go back over the instructions and see if you did anything wrong. Nine times out of ten, it’s something simple but so small and insignificant that it’s easy to overlook. You may have left out a required comma between two values, or forgotten a quotation mark. Perhaps you misspelled the URL of a Web site. Go over everything you did very carefully, and you’ll usually find the problem.
If the script is fine, make sure that you uploaded all the necessary files. Some scripts have data files that you need to upload along with them in order for them to work properly.
Check to see that your cgi-bin folder has the correct permissions settings. If you’re not familiar with permissions, ask your ISP to check them for you.
If all else fails, send an e-mail message to the program’s author explaining the nature of the problem and ask for help. Because most of these programs are free, don’t expect too much in the way of technical support. Nobody can afford to both give away programs and spend all their time providing free technical support as well. The best approach is to be polite, perhaps tell the program’s author how much you want to use the program (if you don’t feel that way about it, you haven’t come this far), and make sure that you give all the information you can about the settings you used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.156.35