12 Running CGI Scripts
PDF 417 Recognizer In .NETUsing Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in VS .NET applications.
entered in your Web form) or how many bounces you will get when your mailing list system finds thousands of @AOL or user @ aol type of data errors Sanity check user data CGI scripts are often the target of many security attacks If your CGI script accepts user input make sure you validate user data before making use of it
PDF417 Generation In .NETUsing Barcode generation for VS .NET Control to generate, create PDF417 image in .NET framework applications.
Before you start reinventing the wheel, check the Comprehensive Perl Archive Network (CPAN) site at http://cpanperlcom for existing Perl modules that you can use to solve your current problem or to reduce your development efforts by reusing existing CPAN modules In this section, I use many CPAN modules for building CGI scripts Whenever you see a module listed in any of the scripts discussed here, you can add the module to your system using the CPAN module that is shipped with standard Perl Apache for Windows users should consult Perl documentation for how to use CPAN modules because it differs from the standard approach discussed here See also the Windows-specific section of this book for details
PDF-417 2d Barcode Decoder In .NETUsing Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
Note
Bar Code Creator In Visual Studio .NETUsing Barcode drawer for .NET Control to generate, create bar code image in .NET framework applications.
For example, say that you see a script list a module called HTML::Template and would like to install this module so that you can run the script that uses it To install the CPAN module, run perl -MCPAN -e shell from the command prompt as root
Bar Code Recognizer In .NETUsing Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Note
Make PDF 417 In C#Using Barcode printer for Visual Studio .NET Control to generate, create PDF 417 image in .NET framework applications.
If you are running the perl MCPAN e shell command for the first time you will be asked to configure the current CPANpm module, which is used to install other CPAN modules Simply follow the instructions and prompts to configure the CPANpm module and then proceed to the discussion below
Creating PDF-417 2d Barcode In VS .NETUsing Barcode generation for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
After you are at the CPAN prompt, run the install HTML::Template command to install the module The CPAN module will install this module for you If it complains about a dependency, you might have to install some other modules before you can install a module that depends on other CPAN modules After you re done, run quit from the CPAN prompt to return to shell
PDF417 Generator In VB.NETUsing Barcode maker for Visual Studio .NET Control to generate, create PDF-417 2d barcode image in .NET framework applications.
If you do not want to run the interactive CPAN shell using perl -MCPAN -e shell to install a module, you can run perl -MCPAN -e CPAN::Shell->install (modulename) instead For example, perl -MCPAN -e shell CPAN:: Shell->install(HTML::Template) will install the HTML::Template module You can also run this command from a shell script
Barcode Generator In Visual Studio .NETUsing Barcode drawer for VS .NET Control to generate, create barcode image in .NET applications.
Analyzing a simple CGI script
Draw Universal Product Code Version A In Visual Studio .NETUsing Barcode maker for .NET framework Control to generate, create UPC Symbol image in .NET applications.
CGI scripts are typically used to take user input and perform one or more operations based on the input and return results in a HTML page In this section I show you how to create a simple script to get started and to understand CGI scripting concepts The script that we will develop here will perform a single task: it will take a user s full name, format it properly, and return a personalized greeting message Listing 12-2 shows greetingspl script that does exactly that
Barcode Encoder In VS .NETUsing Barcode printer for Visual Studio .NET Control to generate, create barcode image in .NET applications.
Part III Running Web Applications
Encoding ABC Codabar In .NET FrameworkUsing Barcode generator for VS .NET Control to generate, create Monarch image in .NET framework applications.
Listing 12-2: greetingspl
Data Matrix 2d Barcode Creator In Visual C#.NETUsing Barcode maker for .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
#!/usr/bin/perl # # # Name: greetingspl # # Purpose: # # Show a greeting message # ########################################################## use strict; use CGI; # # Get user data # my $query = new CGI; my $name = $query->param( name ); # # Process data # $name = lc($name); my @strArray = (); foreach my $str (split(/ /,$name)) { push(@strArray, ucfirst($str)); } my $formattedName = join( , @strArray); # # Display results # print $query->header; print $query->start_html( Greetings ); print $query->p( Hello $formattedName , ); print $query->p( Thanks for coming to our Web site ); print $query->end_html; # # Terminate # exit 0;
EAN-13 Supplement 5 Encoder In JavaUsing Barcode creator for Java Control to generate, create GS1 - 13 image in Java applications.
12 Running CGI Scripts
Data Matrix Generator In Visual Basic .NETUsing Barcode generation for VS .NET Control to generate, create DataMatrix image in VS .NET applications.
Now, lets take a close look at this script The very first line is a special line:
Barcode Printer In Visual C#Using Barcode drawer for .NET framework Control to generate, create bar code image in VS .NET applications.
#!/usr/bin/perl
UPC Symbol Maker In VS .NETUsing Barcode creation for ASP.NET Control to generate, create UPC-A image in ASP.NET applications.
This line tells the system to run Perl whenever executing this script If you have installed Perl in a non-standard directory, then you must modify this line accordingly For example, if you installed Perl in /usr/local/bin/perl, then you must change this line to reflect that All the lines (other than the very first one) that start with a # sign are a commented out and ignored by Perl The next code segment is:
Scan Barcode In JavaUsing Barcode decoder for Java Control to read, scan read, scan image in Java applications.
use strict; use CGI;
Barcode Printer In JavaUsing Barcode creation for Java Control to generate, create barcode image in Java applications.
The use strict is a Perl pragma (think of pragma as a directive), which tells Perl to evaluate the script for unsafe programming habits The next line tells Perl to load a popular module that is now part of the standard Perl distribution, module called CGIpm, which makes writing CGI programs very easy This modules handles all the underlying details of getting input data that are passed onto the script via STDIN by the Apache server, parsing and decoding input fields, providing methods for displaying content headers, creating HTML contents, and so on It is simply the super -CGI module available to you No one should write CGI scripts in Perl without the CGIpm module The only exception to that rule is if you have a resource constraint and don t want to load a large module each time a script is called But in most cases, this is not an issue, especially since because I do not recommend CGI solutions for high -volume Web sites The next code segment is:
Recognize Code-128 In VS .NETUsing Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications.
my $query = new CGI; my $name = $query->param( name );
Here a new CGI object called $query is created and the param() method of the $query CGI object is called to get the value for the user input name The value for this input is stored in $name variable For example, if the greetingspl script is called as follows: