CGI and PHP Review

CGI Programming

What is CGI-scripting? Stands for Common Gateway Interface: a standard way for interfacing between a web server and a user program, allows for dynamic web content vs. just the static content which regular .html provides

Draw a simple picture of a web client, web server, and show that the cgi program runs on the web server.

When client uses URL which specifies a cgi program, the web server recognizes that it is a cgi program based off of its extension .cgi or .php3. Instead of displaying the file it runs the program and displays the programs output. The output of the program should be htmlized.

What languages can we use to make a cgi program?

Passing parameters to CGI scripts
GET vs. POST
The GET method will put the parameter list (eg. var1=3&var2=hello) into an environment variable which usually has an 80-255 character limit. The POST method sends the parameter list to the program through the standard input stream.

Passing parameters through a URL
Uses the GET method.
    http://your.server/test.php3?var1=Hello&var2=5

Passing parameters through an HTML Form
Specify which method to use in the FORM tag.
    < FORM ACTION="test.php3" METHOD="POST" >
    < INPUT TYPE=text NAME=var >
    < INPUT TYPE=submit >
    < /FORM>

PHP

PHP Basics Getting CGI input values (Let's say you don't know parameter names)
<?php_track_vars?>
<?
        print "Values submitted via POST method:<br>";


        /* reset() rewinds the given array's internal ptr to first elem */
        reset($HTTP_POST_VARS);

        /* list() - isn't really a function, assigns a list of
           vars in one operation, in this case each returns a
           key, value pair which list is assigning to $key and
           $val */
        while (list ($key, $val) = each ($HTTP_POST_VARS)) {
                print "$key => $val<br>";
        }
?>

Related Web Sites


mstrout@cs.ucsd.edu .... May 24, 2000