Using CGI and SSIs

CGI, the Common Gateway Interface, is a way for you to do things with you page that you can't do with plain HTML. For example, you can get feedback from the users or your page, generate pages "on-the-fly," and include the current date and time on your page.

Using CGI/Perl Scripts to handle forms

If you put forms on you page, you'll need a way to handle the data people enter into them. Scripts are what you need. Scripts are "simple" programs written in a language like Perl, one of the more common CGI script languages, that can handle the information sent to them. Writing a script from scratch is not all that easy, especially if you've never done any programming before. You'll spend hours trying to learn Perl (or any other language) just to make your forms work. You may be able to find a script on the Net that someone's written for people to download, but getting those to work on your web page can be very difficult, especially since the instructions that come with them are usually pretty bad. For all those people out there who've run into this problem, or don't want to, here's a free script, with easy directions on how to use it.

First, here's what the script will do:

Here's what you need to do to use the script on your web page:

#!/usr/local/bin/perl #This is the path of the perl interpreter. You may not need to change this, but check with your ISP


print "Content-Type: text/html\n\n";

$datetime = `date`;
$browser = $ENV{'HTTP_USER_AGENT'};

if ($ENV{'REQUEST_METHOD'} eq "GET") {
	$input = $ENV{'QUERY_STRING'};
	}
	elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
	read (STDIN,$input,$ENV{'CONTENT_LENGTH'});
	}


$input =~ s/\&/\n<br>/g;
$input =~ s/\+/ /g;
$input =~ s/%(..)/pack("c",hex($1))/ge;

open(outputfile,">>../feedback/feedback.txt"); #this is where you put the full name of the file that you want the script to write to. In this case, it will write to feedback.txt in the feedback directory.
print (outputfile "$datetime \n<br>  $input \n<br> Browser=$browser <p><hr><p>");
close(outputfile);


print <<"End_html";

<html>
<head>
<title>Thank You!</title>
</head>
<BODY BGCOLOR="#FFFFFF" LINK="#FF0000" VLINK="#C40000" ALINK="#FF0000" >

This is where you can put in whatever HTML tags you want. This HTML will show up when the user submits the form. 


End_html


Using Server-Side Includes

Server-Side Includes (SSI's) are a way of putting data into your web page without having to manually enter it. You can add the current date, when a particular file was last updated/modified, and many other things, including a whole web page.

Here's how SSIs work: SSIs are commands on a web page enclosed in the HTML comment tag (<!-- a comment or SSI -->. When someone loads your web page, the server will recognize the command as it sends your page and plug in the data asked for, instead of the text of the SSI.

For example, the SSI <!-- #flastmod file="mypage.html" --> will tell the server to send the date and time of when mypage.html was last modified. flastmod is a UNIX command the server understands. In case your wondering, flastmod means File Last Modified.

Guidelines for using SSIs/Why yours won't work:

SSIs are really easy to use, just make sure you follow the following guidelines:

Here's a list of SSI's that you may want to use on your page: