Whats And Whys Of CGI! Learn The Basics Of A CGI Script

The Common Gateway Interface (CGI) is a standard for connecting applications with information servers, like HTTP or Web servers.

A plain HTML document is static, which means it stays the same just displaying your message. No chance for the visitor (client) to interact. A CGI program, is interactive in real-time, so that it can output information at a moment's notice.

Examples of what CGI can do for you would be a guestbook, free for all ad site, classified ads sites, online greeting cards, surveys, and forms.

For those not skilled in programming, there are many resources around the web for you to pick up a script, but you will still need to know a bit about CGI in order to make it work.

When you need a script, go to one of these sources for an easy to install program

A CGI program is executable which means anyone can run this program at the expense of your site. This isn't the safest thing to do, so security precautions need to be in place.

In some host sites, you will see a directory called a /cgi-bin. This is the special directory where all of your CGI programs reside. A CGI program can be written in any language for it to be executed such as AppleScript, C/C++, Fortran, PERL, TCL, or Visual Basic.

In creating a CGI document, on the first line at the very top should be your path to the CGI-bin. A path specifies the location of a file or directory (folder) on a computer. A simple path looks like this:

/user/crib/notes

setting cgi permissions picture shows one column down the left side to check off for owner group and others up against the top row of read, write and execute in a grid form

Chmod - change access permission (mode) of a file

There are two ways to change permissions: through symbolic or numeric form. This section describes the numeric form. Chmod is a set of 3 numbers that have a specific action for your file. The first number is the owner, the second number is the group and the third number is for the others. To figure out what number is to be assigned, you need to add in the factors of what will be permitted. 4 means to read, 2 means to write and 1 means to execute. So if you want the owner to read, write and execute the file, you would have to add the numbers 4+2+1 together and put 7 in the first section for the owner permission. If you wanted everyone else (group and others) to just read and write to the file, you would add 4+ 2 in order to get the permission 6 which you would put in the slot for group and others. So this would read 766.

The modes are as follows:

111

Owner has execute permission
Group and Others have execute only permission

122

Owner has execute permission
Group and Others have write only permission

144

Owner has execute permission
Group and Others have read only permission

211

Owner has write permission
Group and Others have execute only permission

222

Owner has write permission
Group and Others have write only permission

244

Owner has write permission
Group and Others have read only permission

311

Owner has write and execute permission
Group and Others have execute only permission

322

Owner has write and execute permission
Group and Others have write only permission

344

Owner has write and execute permission
Group and Others have read only permission

511

Owner has read and execute permission
Group and Others have execute only permission

522

Owner has read and execute permission
Group and Others have write only permission

611

Owner has read and write permission
Group and Others have execute only permission

622

Owner has read and write permission
Group and Others have write only permission

644

Owner has read and write permission
Group and Others have read only permission

711

Owner has read/write/execute permission
Group and Others have execute only permission

722

Owner has read/write/execute permission
Group and Others have write only permission

733

Owner has read/write/execute permission
Group and Others have write and execute permission

744

Owner has write and execute permission
Group and Others have read only permission

755

Owner has read/write/execute permission
Group and Others have read and execute permission

766

Owner has read/write/execute permission
Group and Others have read and write permission

666 or 777

Owner, Group and Others have read, write and execute permission

Of course there are other combinations, but this will help you get started in figuring out what you need.

One of the most common reasons a script will not work is because the permissions are not correctly set. Another biggie is when a file that should be uploaded as a binary file is uploaded as an ASCII or an ASCII file is uploaded as a binary file. So if you have a script and you are wondering why it just won't work, first look at the permissions. If the permissions are correct, delete them and try uploading them in a different format.

These will help the beginner get started, but there is so much to this that you would need a special class to teach you or a lot of books to read.

Free CGI Resources

  1. CGI Free Hosting
  2. CGI City
  3. Free CGI Scripts: PERL
  4. Matt's Script Archive
  5. Selena Sol's CGI Script Archive
  6. Best-Of-Web.com CGI Scripts 
  7. WebScripts
  8. FreeForm
  9. Selena Sol's Script Archive
  10. The CGI Resource Index
JCE Enterprises Web Sites

JCE Enterprises Related Sites