CGI Introduction Program

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

You begin with the traditional introductory programming problem. You want to write a program that will display " Hello, world! " on your Web browser. Before you can write this program, you must understand what information the Web browser expects to receive from CG I programs. You also need to know how to run this program so you can see it in action. The "Hello, world!" program looks like

#!/usrl/local/bin/perl
# the above line is necessary is Unix platform for informing the
# web server the perl interpreter's location
# ------hello.cgi - My first CGI Program
print "Content-Type:text/html\n\n";
print"<html><head>\n";
print<title>Hello, World!</title>";
print "</head>\n";
print "<body>\n";
print"<h1>Hello, World</h1>\n";
print"</body></html>\n":

Save this program as hello.cgi, and install it in the appropriate place. For most people, the proper directory is called cgi bin. Now, call the program from your Web browser, For most people, this means opening the following Uniform Resource Locator (URL):

http://hostname/directoryname/hello.cgi
" hostname " is the name of your Web server, and " directoryname " is the directory in which you put hello.cgi (probably cgi bin). Your first CGI program, if all goes well, will display Hello, world!.

There are couple of things worth mentioning about hello.cgi. First, you're using simple print commands. CG I programs do not require any special file handles or descriptors for output. In order to send output to the browser, simply print to the stdout.

Secondly, notice that the content of the first print statement (Content Type'. text/ html) does not show up on your Web browser. You can send whatever information you want back to the browser (an HTML page or graphics or sound), but first, you need to tell the browser what type of data you're sending it. This line tells the browser what sort of information to expect; in this case, an HTML page.

Third, the program is called hello.cgi. It's not always necessary to use the extension cgi with your CGI program name. Although the source code for many languages also use extensions, the cgi extension is not being used to denote language type, but is a way for the server to identify the file as an executable rather than a graphic file or HTML or text file. Servers are often configured to try to run those files which have this extension, displaying the Content all others. Although it might not be necessary to use the cgi extension good practice.



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.