The Basics of CGI Developer's Guide - 2. Hello, World!
Hello, World!
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 CGI programs. You also need to know how to run this program so you can see it in action.
CGI is language-independent, so you can implement this program in any language you want. A few different ones are used here to demonstrate this language independence. In Perl, the "Hello, World!" program looks like Listing 2.1.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Listing 2.1. Hello, World! in Perl.
#!/usr/local/bin/perl
# 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. (If you are not sure where that is, relax; you'll learn this in "Installing and Running Your CGI Program," later in this chapter.) For most people, the proper directory is called cgi-bin. Now, call the program from your Web browser. For [ 瀏覽完整內容請先註冊或登入會員。]
|