Client Services Enterprise Operations & Solutions Teaching & Learning (CITL) Information Security

CGI Scripts

A Common Gateway Interface (CGI) Script is an executable program that allows a user to exchange information with a website. Because CGI is a protocol and not a specific language, CGI scripts can be written in a number of different languages, including Perl.

Writing a CGI Script in Perl

To write a CGI Script in Perl, follow the instructions below. These instructions will only work on a UNIX machine.

  1. To create a new CGI script, you need to log in to a remote server via SSH Secure Shell or Telnet. For Stern students, this server is sales. For faculty the server is grid and for admins the server is eureka.
  2. Every CGI script you create must be saved with a .cgi extension.
  3. Every CGI script needs a header, which specifies where Perl is located on the computer. An example of a header is:
    #!/usr/local/bin/perl
  4. You might also find it helpful to add in the following command to help with processing the data:

    use CGI qw(:standard :cgi-lib);

  5. In order to print any text to the browser you must first add in the command:

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

  6. When you are finished writing your script, you must grant permission for the CGI script to be executed by the web server. The command to change permissions is chmod. To allow others to read and execute your CGI script you need to change the permissions to 755.

    chmod 755 filename.cgi

    (where filename is substituted with the name of your CGI script)