CGI Common Gateway Interface

  • Intro to CGI


    Q. Are there alternatives to CGI?
    A. Yes. I recommend you use PHP instead (It runs as a module under Apache).

    Q.How does it differ from html?
    A.CGI scripts generally end up producing html, but they are produced by the server at the moment the script's address is requested by the browser. This dynamic aspect allows for the end content to be different depending on various circumstances (time, user, accumulated data)

    Q.What language is CGI written in? Is it a language?
    A.CGI is a protocol, and it can be implemented using most any language that's supported on the server. C, Perl or others.

    Q.Are there things one should avoid?
    A.Many things:

  • Perl, unless you're a masochist.
  • You need to remember 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.

    Q.What info do I have at my finger tips?
    A.In addition to time and environment variables, you can set up a database that can grow and grow...

    Q.How do I get info from users?
    A.Forms are one way. Look here for details. It's a bit tricky to "parse" the input from a POST method with C-shell, so I'll go over a method in class.

    Q.How do I use CGI to redirect to a new URL based on some condition?
    A.You could use the content type and "Location" keyword in your script, such as:
    Content-type: text/html
    Location: gopher://