www.createasite.net
freewh.890m.com

CGI Script

What is a CGI script?

A CGI script is like a program. It is a collection of lines of code that contain instructions for a computer. Programs, however are compiled so that they will run faster on a particular OS. CGI scripts are just simple text files that are interpreted as needed. CGI scripts are smaller and simpler than programs.

CGI scripts can be written in Perl, PHP, C, Visual Basic, Python or whatever. Perl and PHP seem to be the languages of choice. That's because they are easy to learn and are very portable.

Not all Perl scripts are CGI scripts. Only Perl Scripts that follow CGI protocol are CGI scripts.

Sample Perl/CGI Script

The CGI script written in Perl has a very simple structure. The CGI script shown below would print the words Hello World to the PC screen. The shebang line tells the browser where to find the Perl interpreter on the server. The content header tells the browser what kind of content to expect.

#!perl #shebang line
print "Content-type:text/html\n\n"; #Content Header

print <<End_of_Doc;
<html>
<head><title></title></head>
<body>
Hello World
</body>
</html>
End_of_Doc

Sample PHP Script

To do the same thing with PHP the code is:

<html><head></head>
<body>
<?php print "Hello World"; ?>
</body>
</html>

PHP/MySQL

PHP is especially useful when working with relational databases and MySQL. For information on this subject, visit our PHP/MySQL Tutorial.

CGI Scripts and HTML Forms

One common use of a CGI script is to process the data collected on an HTML Form. A form contains input devices. Text boxes, textareas, check boxes, radio buttons and selection boxes are all examples of these input devices. The name of the the processing CGI script is placed in the action attribute of the form structure.
<form method="POST" action="cgi-bin/parse_post.pl">
In this section of code a CGI script named parse_post.pl found in the cgi-bin directory is named in the action attribute.

The browser accesses the CGI script when the Submit button on the form is pressed.

Free HTML Form Template Kit

You can download our free form template kit. The kit includes a form for receiving personal information from a user and 2 CGI scripts for processing the data. There is an actual active demo of the HTML form on the page so you can try it out.


What is CGI? Create a website with Yahoo Site Solutions or SiteBuilder CGI Script Gallery

Net Success 2000 Plus Inc
PO Box 1508
Somerset, KY 42502
Copyright 2000 - 2006 Net Success 2000 Plus Inc
Last Modified: August 11, 2006

|HTML OnLine | Website Tutorial |