The Apache Webserver accepts plugins (generally called something_mod) to add new kinds of requests to a web site. When a request is received for a page ending in .php (rather than .html) it the webserver invokes the php system.

Ok, so what is the php system? PHP, which initially stood for Personal Home Page, is a server-side scripting language. When a web server receives a request for a php page, it generates a page by executing a script which may (and frequently does) consult a database, rather than fetching a static .html page. The php system associates a web server request with the execution of a specific php script, and it returns the output of that execution as the response to the web request.

The MyList application demonstrates the basics of using PHP. This script presents a page that will build a list of items entered by the user. To try it, click on the MyList link and type text in the text box displayed on the page. When you click on submit (or press Enter), the text in the box should be added to a list of words and the box cleared. The source code is at the bottom of this page. Scrolling down you will find two distinct sections: the first twelve lines of the source code (begining with the characters <? and ending with ?>) make up the main executable part of the script; the remainder of the code begining with <HTML> and ending with </HTML> contains a model of the output to be generated to your browser. I will discuss each of the two sections separately but first a few general comments:
  1. all text between <? and ?> is treated as executable code by the PHP system
  2. within the exectutable codes variables start with a '$' sign
  3. all text outside of <? and ?> is passed to the browser unchanged.
Now let's look more closely at the ExecutablePart and the the ModelPage portions of the code.

// $listContents = $HTTP_GET_DATA["listContents"];
if (!isset($tail)) {
$myList = array();
else {
$myList = explode("|",$listContents);
$indx = count( $myList );
$myList[ ($indx) ] = $tail;
$listContents = implode($myList,"|");

<H1>My List</H1>
A simple PHP Application<br>
Steve Hirst (c) 2004-Jan-02

for( $idx=1; $idx<count($myList); $idx++ ) {
print( "<LI>".$myList[$idx]);

<FORM ACTION="mylist.php" METHOD="GET">
New Item: <INPUT TYPE="TEXT" NAME="tail" >
<INPUT TYPE="HIDDEN" NAME="listContents" VALUE="<? print($listContents) ?>">
<A href="tiki-index.php?page=SomethingCalledPHP">SomethingCalledPHP</a>

Created by steve. Last Modification: Saturday 21 of February, 2004 16:04:39 EST by kristin.