The numbered lines on the page are the main executable part of mylist.php (the script for MyList). The first line, consisting of only <?, tells the php system that an executable portion begins. The second line is a comment. If the first two characters were removed it would assign the string associated with the form variable listContents to the variable $listContents. Since PHP does this by default, I made this line a comment. Every cookie and form variable is mapped to a PHP variable with the same name.
The first time we access the page there will be no such form variable and the value will be set to the empty string. Line #03 tests to see if the varible $tail is set; this variable will be set only if there was either a cookie or form variable of that name. If you look at the ModelPage portion of the page you'll see that tail is the name of the text field on the page. (Note: if you are not familiar with cookies and html forms, take a quick look at FormsAndCookies ). If we get to this page from outside (i.e. by clicking on the link above) the $tail variable will be unset and $myList will be set to an empty array in line #05.
The page displayed consists of a form with a single text field ("tail") and a button to add the contents of the text field to the list. When this happens, the variables $listContents and $tail will be set to the current contents of the list and the text to be added. If you click on MyList and then type "Sample" in the text field and click on the Submit button, you will see the following url in the address field of your browser: "http://www.wasteflake.com/mylist.php?tail=Sample&listContents=". When this executes the code below: $tail will equal "Sample" and listContents will equal the empty string. Line #07 translates the empty string into an array with one elment in position #0. Line #08 sets the variable #indx to 1 (the number of elements in the array. Line #09 puts the value of $tail into position 1 of the array.
01 <?
02 // $listContents = $HTTP_GET_DATA["listContents"];
03 if (!isset($tail)) {
04 $myList = array();
05 }
06 else {
07 $myList = explode("|",$listContents);
08 $indx = count( $myList );
09 $myList[ $indx ] = $tail;
10 }
11 $listContents = implode($myList,"|");
12 ?>
The first time we access the page there will be no such form variable and the value will be set to the empty string. Line #03 tests to see if the varible $tail is set; this variable will be set only if there was either a cookie or form variable of that name. If you look at the ModelPage portion of the page you'll see that tail is the name of the text field on the page. (Note: if you are not familiar with cookies and html forms, take a quick look at FormsAndCookies ). If we get to this page from outside (i.e. by clicking on the link above) the $tail variable will be unset and $myList will be set to an empty array in line #05.
The page displayed consists of a form with a single text field ("tail") and a button to add the contents of the text field to the list. When this happens, the variables $listContents and $tail will be set to the current contents of the list and the text to be added. If you click on MyList and then type "Sample" in the text field and click on the Submit button, you will see the following url in the address field of your browser: "http://www.wasteflake.com/mylist.php?tail=Sample&listContents=". When this executes the code below: $tail will equal "Sample" and listContents will equal the empty string. Line #07 translates the empty string into an array with one elment in position #0. Line #08 sets the variable #indx to 1 (the number of elements in the array. Line #09 puts the value of $tail into position 1 of the array.
01 <?
02 // $listContents = $HTTP_GET_DATA["listContents"];
03 if (!isset($tail)) {
04 $myList = array();
05 }
06 else {
07 $myList = explode("|",$listContents);
08 $indx = count( $myList );
09 $myList[ $indx ] = $tail;
10 }
11 $listContents = implode($myList,"|");
12 ?>