Sample CGI Code

NOTE:Make sure that all your CGI programms are in the directory cgi-bin and all Perl and Python programs can be executed by execute Linux command: chmod. For example, if the name of your cgi program is adduser.pl, you can execute the command: chmod a+x adduser.pl

Writing a cgi program entirely in Perl

  • tinyPL.cgi
    This is an example Perl program that just writes a static web page. No form is necessary to call it.
  • tinyPL.html
    This Web page calls tinyPL.cgi.

  • adduserPL.cgi
    This is an example Perl program that is called from the html page adduserPL.html. The Perl program receives the http string, parses the arguments, then outputs the resulting Web page.

  • adduserPL.html
    This is the web page that calls adduserPL.cgi.
  • A C++ program that generates HTML Output

  • Makefile
    The Makefile that compiles all of the examples below.
  • adduserpgm.cpp
    This is an example C++ program that is called from the command line and produces valid HTTP output. A sample call would be: adduserpgm.exe -u Luke -p 1234

    Creating a cgi program by calling a C++ program from a Perl script.

  • adduserPLC.cgi
    This is an example Perl program that is called from the html page adduserPLC.html. The perl program receives the http string, parses the arguments, then does a system call to adduserpgm.exe.

  • adduserPLC.html
    This is the web page that calls adduserPLC.cgi.

  • Writing a cgi program entirely in C++

  • addusercgi.cpp
    This is an example C++ program that is called from the html page adduserC.html. The C++ program receives the http string, parses the arguments, then calls a function to do the work. There is no system call necessary.

  • adduserC.html
    This is the web page that calls adduserC.cgi.

  • cgi.cpp
    This is a C++ class that contains better ways to parse http strings.

  • cgi.h
    This is the header for the cgi.cpp class.

  • Creating a cgi program by calling a Java program from a Perl script.
  • adduserPLJ.cgi
    This is an example Perl program that is called from the html page adduserPLJ.html. The perl program receives the http string, parses the arguments, then does a system call to java addusercgiJ

  • addusercgiJ.java
    This is the Java program that, given the username and password, echos them back in a HTML page. Do View Source to see the program nicely formatted.

  • adduserPLJ.html
    This is the web page that calls adduserPLC.cgi.
  •        
        Writing a cgi program entirely in PHP

  • tiny.php
    This is an example PHP program that just writes a static web page. No form is necessary to call it. It must reside in your cgi-bin directory. The filename must end in php.
  • tinyPHP.html
    This Web page calls tiny.php at EECS.

  • adduser.php
    This is an example PHP program that is called from the html page adduserPHP.html. The PHP program receives the http string, parses the arguments, then outputs the resulting Web page.
  • adduserPHP.html
    This is the web page that calls adduser.php.
  •        
        Writing a cgi program entirely in Python

  • tiny.py
    This is an example of Python program that just writes a simple web page. No form is necessary to call it. It must reside in your cgi-bin directory. The filename must end in py.
  • tinyPY.html
    This Web page calls tiny.php at EECS.

  • adduser.py
    This is an example of PY program that is called from the html page adduserPY.html. The Python program receives the http string, parses the arguments, then outputs the resulting Web page.
  • adduserPY.html
    This is the web page that calls adduser.py.


  •        
       Debugging a script