Our Community

DomainGurus Forums » Technical Questions

What is CGI and how do I use it?

(1 post)

Tags:

  1. What is CGI and how do I use it?


    The Common Gateway Interface (CGI) is a standard for interfacing external applications with information servers, such as HTTP or Web servers. A plain HTML document that the Web daemon retrieves is static, which means it exists in a constant state: a text file that doesn't change. A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information.

    For example, let's say that you wanted to "hook up" your MySQL database to the World Wide Web, to allow people from all over the world to query it. Basically, you need to create a CGI program that the Web daemon will execute to transmit information to the database engine, and receive the results back again and display them to the client. This is an example of a gateway, and this is where term CGI originated. There really is no limit as to what you can hook up to the Web. The only thing you need to remember is that whatever your CGI program does, it should not take too long to process. Otherwise, the user will just be staring at their browser waiting for something to happen.

    Since a CGI program is executable, it is basically the equivalent of letting the world run a program on your system, which isn't the safest thing to do. Therefore, there are some security precautions that need to be implemented when it comes to using CGI programs. Probably the one that affects the typical Web user the most is the fact that CGI programs need to reside in a special directory, so that the Web server knows to execute the program rather than just display it to the browser. This directory is usually under direct control of the webmaster, prohibiting the average user from creating CGI programs.

    If you click on the File Manager icon to the right of your domain at Domains > List all Domains, you will see the contents of your web site, which includes a directory called /cgi-bin. This is the special directory mentioned above where all of your CGI programs currently reside. A CGI program can be written in any language that allows it to be executed on the system. If you use a programming language like C or Fortran, you must pre-compile the program before it will run under the /cgi-bin directory. If, however, you use one of the scripting languages instead, such as Perl, the script itself only needs to reside in the /cgi-bin directory, since it is an interpreted language (you will need to include the path path to Perl interpreter). Most people prefer to write CGI scripts instead of programs, since they are easier to debug, modify, and maintain than a typical compiled program.

    If your are writing CGI scripts to make your website more dyanamic, we highly recommend considering using a scripting language called PHP. This language is rapidly becoming the most commonly used method for web developers to write dynamically generated pages quickly.

    Posted 1 year ago #

Reply

You must log in to post.