FIT3084 : Perl CGI Script

 

A sample database file containing student names, ID numbers and marks is provided.

Tips and tricks to help you get your CGI scripts working:
  1. Check that you have set everything up properly according to the instructions online here: https://users.monash.edu.au/about/

  2. Make sure that any Perl CGI scripts you have end with extension .cgi On users.monash, PHP scripts must end with .php

  3. Make sure that any CGI scripts you have reside in your directory www/cgi-bin or a sub-directory of this. They should not be directly in the www directory with your XHTML files or the web server won't be able to find them.

  4. If you are using Perl, you need to find the Perl interpretter on the users.monash.edu.au system (or whatever system your web page is served from). Login to the web server.
    Then, you can use the UNIX command which (type man which for instructions). If Perl is in your path, which will tell you where it is. e.g. when I type it on my machine prompt I get:

    > which perl
    /usr/bin/perl
    >

    You might find Perl somewhere else! If it is not in your path, go and look in /usr/bin and around there to see if you can find it manually.
    Be sure to include the first line of the perl script as #! then the path to Perl. Do not indent the #!, it must be in the leftmost column on the first line of the file.

  5. Make sure that your Perl script is executable (do an ls -l) to check, or chmod +x yourFileName.cgi to ensure this. The permissions should at least be: -rwx------

  6. Try running the Perl script directly from the command line under UNIX. Does it work ok? To do this, you might need to comment out any need for input CGI parameters (or pass them to the Perl script from the command line or environment variables) then type:

    > perl test.cgi

    at the prompt.

  7. Open the CGI script in the vi text editor on the Unix web server. Make sure it has no funny ^M characters at the end of the lines. These are often inserted when you edit the file using a Windows text editor. Windows uses \n\r at the end of each line, UNIX only requires \n. If the ^M characters are there, remove them from the file (In vi, globally replace them with nothing).

  8. Try adding a blank line to the end of the script file after the last line of code. Some interpretters need this after the last line of code.

  9. Make sure that before you print anything out from your CGI script, you return the header information to the client. You can do this using the CGI.pm method print header; or with a normal print statement print "Content-type: text/html\n\n"; Don't forget the double newline!

 


Lecture notes

© Copyright Alan Dorin 2009