Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ . ]
 
[ Web Magic ]

CGI Tips and Tricks
Things you Should Know

[ line ]

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

 
Looking for a great database script? Check out Gossamer Threads DBMan Database Administrator & WebMagic's Unofficial DBMan FAQ.


What is CGI?

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:

<FORM METHOD=POST ACTION=http://www.mybusiness.com/cgi-bin/formprog.pl>

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.


What is FastCGI?

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.

[ Back to Top ]


HTTP Status Codes

100continue
101switching protocols
200ok
201created
202accepted
203non authoritative
204no content
205reset content
206partial content
300multiple choices
301moved permanently
302moved temporarily
303see other
304not modified
305use proxy
400bad request
401unauthorized
402payment required
403forbidden
404not found
405method not allowed
406not acceptable
407proxy authentication required
408request timeout
409conflict
410gone
411length required
412precondition failed
413request entity too large
414request uri too large
415unsupport media type
500internal server error
501not implemented
502bad gateway
503service unavailable
504gateway time out
505version not supported

Common Internet Messages

[ Back to Top ]

Debugging - How To Obtain Useful Error Messages:

A very simple solution which displays errors within your browser is to add:

use CGI::Carp qw/fatalsToBrowser/; # For testing only

at the top of your script right after the path to perl.

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 {
open (STDERR, ">/path/to/somewhere/error.txt");
}

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.

[ line ]

[ Back to Top | Home ]

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ Creative Computing ]

[ Recommend Our Site ]     [ Creative Computing ]     [ HTML 3.2 Validated ]

Copy & Copyright (c) 1998 - 2006   Creative Computing

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Please Click To Visit Our Friends At:

Home
Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

HTML Tips
HTML Validation
CGI Tips
Web Security
Search Engines
Spam Mail

Online Services
META Tag
    Generator

Web Whois

Site Resources
Site Links
Earn Cash

DBMan FAQ

Creative Computing

Contact
Guest Book

[ Recommend ]

[ Site Map ]

    [ Cross ]

[ Creative's Health News ]

[.]