About Gekko
Dial-Up Locations
Services and Prices
Resale/Retail Plans
See Our
Sites
Search the Net
Software
Tech Support
Home Page


Gekko Internet Services, Inc.

How to create dynamic
web content and CGI

Sometimes you need to generate a web page (or part of it) dynamically - for example, to display the current date / time, or the count of visitors. Some pages contain forms with input fields and buttons, and you need to process the information entered in the form. We have some commonly used programs which may be useful to you: form processing, counters, etc. This document assumes that you are familiar with the HTML language, or at least you know how to insert HTML source code in your web page. The following information contains texts specific for the OS platform of your web server. If you are not sure if your web server is on a Unix or NT platform please check with webmaster@gekko.net


Using JavaScript

JavaScript is a scripting language which is interpreted by the web browser. Currently, only Netscape Navigator and Microsoft Internet Explorer support JavaScript. JavaScript is derived from the Java language and is close to C++. JavaScript code is embedded in the HTML within the <SCRIPT></SCRIPT> tag. Here is an example which displays the current date in your page:

<SCRIPT> todayDate = new Date () document.write ("Today is " + (todayDate.getMonth() + 1) + "/" + todayDate.getDate() + "/" + todayDate.getYear() + "<BR>\n") document.write ("Your browser is " + navigator.appName + " " + navigator.appVersion + "<BR>\n") </SCRIPT> Here is the output of the script:
Today is 11/5/97
Your browser is Netscape 4.03 [en] (WinNT; U)

The complete JavaScript manual can be found at Netscape's web site.

Using Server Parsed HTML


Most UNIX web servers can pre-process HTML files. This feature has to be configured on the server. Usually the server would recognize files with special extensions (usually .shtml). The HTML syntax for server-parsed commands is
<--#command attribute=value attribute=value ... --> The following example outputs todays date: <!--#echo var="DATE_GMT"--> More detailed information can be found in the Apache server documentation.

Using CGI scripts (Perl, Unix shell, etc.)


The most common way to create dynamic content is to use CGI - the web server executes a program which generates HTML page as output. There are two methods used to pass information (such as the content of the input fields in a form) to the program: GET and POST. The information is encoded according to the CGI protocol and needs to be decoded. There are common libraries for Perl, C, etc. for handling CGI input. Click here to download a Perl CGI library.

In your web page you need to reference the CGI either as link or as ACTION in the form tag if the CGI is supposed to handle a form. Example:
<FORM METHOD="POST" ACTION="http://www.yourdomain.com/cgi-bin/yourscript.pl"> On NT web servers script file extensions are associated with the interpreter for the language (e.g. .pl files are associated with Perl and will be directly executed).

On Unix web servers the scripts need to begin with #! and the interpreter location (e.g. Perl scripts must start with the line #!/usr/bin/perl5 ). Also, the scripts must have executable permissions for the web server - after you uploaded the scripts, telnet to your web server with your username and password, and change the permissions with the command 'chmod 755 filename'. Some ftp programs support changing permissions as well.

Using CGI executables (C, C++, etc.)


Most CGIs are written in interpreted languages and don't need to be compiled. However, if you are more familiar with another programming language like C or C++ you might prefer to use it for your CGIs.

On Unix web servers C files are usually compiled with the cc or gcc
cc -o file file.c
For C++ you can use the g++ (GNU C++) if it's available on the web server.

On NT web servers you need to compile WIN32 executables at home and upload them.

Protecting files and directories with passwords


Some web servers have features which allow you to protect files and directories with a password. On Windows NT with the Microsoft IIS server an actual user has to be created on the system. Please e-mail support@gekko.net if you'd like to protect a file or a directory with a password on an NT hosted server.

On Unix, the Apache web server allows to limit the access to a directory using a .htaccess file. Detailed description of the .htaccess format can be found at www.apache.org. Here is a short example of protecting a directory:
  1. In the directory which you want to protect, create a .htaccess file which contains:
    AuthUserFile /full/path/to/passfile
    AuthName protected area
    AuthType Basic
    <Limit GET POST>
    require valid-user
    </Limit>
    
  2. Create a file named passfile, in the format:
    username1:password
    username2:password
    ...
    
Note: It's not a very good idea to put the file with the passwords in the protected directory like in the example above, because it could be downloaded.


Gekko Internet Services, Inc.
webmaster@gekko.net
1691A Forum Place - West Palm Beach, Florida 33401
Phone: 561-686-3684    Fax: 561-686-4431
Copyright © 1998 Gekko Internet Services, Inc. ®
Web Site design, layout, graphics and animation created by: Gekko Internet Services