|
|
|
|
CGI Tips and Tricks
CGI Tips & Tricks will provide some basics to using CGI. I am not a CGI programmer but have configured many scripts while building web sites and am always learning. This area will provide some of the tricks and tips I have learned from others or through my own trial and errors. Feel free to contribute to this area of the web site and view the resources provided for further information.
What is Perl? Practical Extraction & Report Language
The common gateway interface (CGI) is a standard way for a Web server to pass a Web user's request to an application program and to receive data back to forward to the user. This method or convention for passing data back and forth between the server and the application is called the common gateway interface (CGI). It is part of the Web's HTTP protocol.
If you are creating a Web site and want a CGI application to get control, you specify the name of the application in the URL that you code in an HTML file. This URL can be specified as part of the FORMS tags if you are creating a form. For example, you might code:
and the server at "mybiz.com" would pass control to the CGI application called "formprog.pl" to record the entered data and return a confirmation message. (The ".pl" indicates a program written in Perl but other languages could have been used.) The common gateway interface provides a consistent way for data to be passed from the user's request to the application program and back to the user. This means that the person who writes the application program can makes sure it gets used no matter which operating system the server uses (PC, Macintosh, UNIX, OS/390, or others). It's simply a basic way for information to be passed from the Web server about your request to the application program and back again. Because the interface is consistent, a programmer can write a CGI application in a number of different languages. The most popular languages for CGI applications are: C, C++, Java, and Perl.
FastCGI is a programming interface that can speed up Web applications that use the most popular way to have the Web server call an application, the common gateway interface (CGI). According to one FastCGI implementor, user requests coming to a Web site and using a specific application program can be handled 3 to 30 times faster using FastCGI. FastCGI is a plug-in to the Web server. It requires only small changes to existing server applications (such as Perl or Tcl scripts and C and C++ programs ) to get the performance benefits.
Debugging - How To Obtain Useful Error Messages:
A very simple solution which displays errors within your browser is to add: OR another solution: To obtain useful error messages, add the following snippet to your script, just beneath the shebang line (the first line of the script; usually !#/usr/local/bin/perl or !#/usr/bin/perl): BEGIN { Now create an empty plain text file named "error.txt" and upload it in ASCII mode to your somewhere/ directory. Chmod it to 777. Now run your script from your browser. After it gives you its error message, call your error.txt from the browser (for example, http://www.your_site.com/somewhere/error.txt; you might make a bookmark for it because, if you're like me, you'll be using it a lot!). The reason for your script's failure should be written there. Note: If you call the error.txt file more than once, you may have to hit your browser's "reload" button. You can use this in your .cgi, .pl, .cfg files and more. Any files associated with your scripts can contain errors, so use this snippet at the top of all your script files. Hope this helps many to find the errors they encounter and find the solutions faster. This has been a great piece of code for me and has saved me hours of debugging time.
[ Back to Top | Home ]
Copy & Copyright (c) 1998 - 2006 Creative Computing
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Home
HTML Validation CGI Tips Web Security Search Engines Spam Mail
Online Services
Site Resources
|