Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.
Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.
To properly display the documents it receives, the Web browsers need to know the types of documents. If the browser receives a plain text file, the file will be displayed in plain text format. If it receives an HTML file, it needs to interpret and display it in HTML format. So when the server sends a document to the client, it should tell the client what type the document is. The standard way to identify the file type is the MIME format. Here are some of the common MIME type/subtypes:
* text/plain: Plain text, which is the default type
* text/html :HTML file (UNIX)
* text/htm :HTML file (wINDOWS NT)
* image/gif: GIF image
* image/jpeg: JPEG image
* audio/x-wav: Microsoft Windows audio format
* video/mpeg: MPEG compressed video
Usually when the server sends a document back to the client, it includes the following:
* A Content-Type: indicates the MIME format.
* A blank line
* The document itself.
Let's look at an example in PERL code:
#!/usr/local/bin/perl
#-------------------------------------------
# post.pl by Zhanshou Yu
#-------------------------------------------
# Get the input for POST method
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
#Split the name-value pairs
($name,$value)=split(/=/,$buffer);
# Substitute special character to its original character
$value=~ tr/+/ /;
$value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
#------print the return HTML------------------
#print the MIME type
print"Content-type: text/html\n\n";
#print the HTML body
print"<html>\n";
print "<head><title>Input For POST method </title></head>\n";
print "<body><center><h1>Input for POST Method </h1>\n";
print "<h2>Here is the string you just input: $value</h2>\n";
print "</body></html>\n";
exit;
The red color code deals with sending the document back to the client. The statement:
Now CGI are used on the web sites very rarely. Still many old sites continuing their CGI scripts. So CGI still plays good role on web scripting. This tutorial helps lot to know more about CGI for a beginner.