![]() |
Sample <FORM> based CGI Program![]() ![]() ![]() ![]() ![]()
This program accepts input from a <FORM> based HTML document and creates an on the fly HTML document. The HTML document is as follows: <html> However, all the data requires similar processing to extract the fields and their values. For this you can use a common set of sub-routines. As you might expect for a popular tool such as Perl, there is already such a Perl library, and that common library happens to be cgi-lib.pl by Steven Brenner. cgi-lib.pI is the accepted library for parsing the CGI query strings that the web server sends to the CGI program. By using the cgi lib.pl library we can quickly create Perl programs to handle form input. The cgi lib.pl library works with both Perl 4 and Perl 5. If your ISP has Perl 5 installed, you may want to use the CGI module, an object oriented CGI processing module that works in Perl 5 only. Because cgi lib.pl is a library of Perl subroutines in a text file, there is nothing much to install. All you need to do is get the latest version of the file and place it in the /cgi bin/ directory of your web server. #reply.cgi The CGI.pm module, developed by Lincoln D.Stein, uses Perl 5's object oriented style of programming. You need Perl version 5.001 or higher to use the CGI module; Perl 5.003 is the recommended version. Like cgi lib.pl library, CGI.pm enables you to accept a query (submitted through an HTML form) and easily extract the parameters submitted by the user, Unlike cgi lib.pl with its procedural interface, CGI pm provides its functionality through a CGI object. To use the CGI.pm module, you begin by inserting the following statement in your Perl script: use CG I; After that, create a CGI object as follows. $a= new CGI; The creation of CGI object involves parsing the CGI query string and extracting all environment variables relevant to CGI programming. $a, will reference to the new CGI object. From then on you can access the methods of the CGI object through the $a reference. Parsing a CGI query is the only one part of the CGI module, and the parsing occurs when you create the CGI object. Additionally, the CGI object has many more features, such as the following: methods for creating HTTP headers that you need to include in HTML documents being sent back from the script methods for creating HTML forms methods for handling advanced features such as frames, Netscape cookies After you create a new CGI object and get a reference to that object, you can begin accessing the parameters in the HTML form's data, To access the parameter by name, call the param method with the name (form element like textbox) as an argument, as follows: $val = $a->param('name'); where $val gets the value entered by the user. To send back an HTML document, begin by calling the print function and invoke the CGI object's header method as argument.
|
|
CGI
Advantages of CGI
How CGI Works
Compiled Versus Interpreted
Input to CGI
CGI Introduction Program
HTML Forms
Accepting Input from the Browser
CGI Environment Variables
Get Versus Post Method
Get Method
Post Method
Sample <FORM> Based CGI Program
Complete Example for <FORM>
Output from CGI
Header and Body:Anatomy of Server Response
HTTP Headers
Carriage Returns and Newlines
Formatting Output CGI Common MIME TypesLocation Header Useful HTTP Stautus Codes Other Headers Dynamic Pages Sending Images Displaying the Current Date Feedback Form Program Server Side Includes Server Side Include Environment Variables Displaying the Date with Date Counter Example of SSI Counting the Number of Accesses Better Approach Towards CGI Program Client Versus Server Accessing a HTML Document Submitting a Form Accessing a CGI Program Databases ODBC Creating a DSN Win32::ODBC Module Creating a Table Inserting Data into a Table Deleting Data from a Table
Updating Data in a Table
Selecting Data from a Table Operating Systems Security Securing Your Web Server Writing Secure CGI ProgramWeb DesignDomain Names Home
FAQ
My Account
IP Address
SSL Certificates DNSWeb Hosting Web Server Cheap Web Design Dedicated web hosting Managed web hostingE Commerce Principles of E-Commerce E-Banking Electronic Payment System E-Security Credit Cards Smart Cards
The Mailbox POP Server SMTP Server IMAP Protocol |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |