FORMS PROCESSING IN PHP PARTNERING

(btw, p4-assign.html is available...)


TASK

1.  Again, find a partner.  It's raining partners.  SO many potential
partners, so few labs.

2.  Sorry again about the foobar during class.  SO you don't believe me?
Think I was covering up for my own incompetence by blaming the sysadmins?
Have a look at this person's Nov 16 blog entry (I buy her art on ebay,
but don't you go driving up her prices):

	Turns out my host upgraded their PHP and it somehow messed up part
	of my blog, and other WP users were voicing complaints too.

In fact, have a gander at the wikipedia entry on PHP, hidden in the
miscellaneous notes:

	The many settings in the PHP interpreter's configuration file
	(php.ini) mean that code that works with one installation of PHP
	might not work with another. For example, if code is written to
	work with register_globals turned on, it won't work on another
	system that has register_globals turned off. This makes it
	necessary to write code that is cross-platform compatible by
	assuming that register_globals will be off and therefore calling a
	global variable with its prefix in front of its name, such as
	$_POST['variable'], $_SERVER['variable'] and
	$_COOKIE['variable'], not, simply, $variable. For more information,
	see the manual page on using external variables.

Damn those sysadmins.  That's the reason why PHP is such a lovely 
beginner's language.  Cause you can say $foo instead of $_SERVER["foo"],
or apparently, now the sysadmins are going to make us say $_GET["foo"].
But we are flexible and they cannot stop us.

You might even read the first paragraph on PHP.  Professor Loui did a 
pretty good job off the top of his head, huh?  I would have mentioned
"pretty hypertext processor" if (1) I'd've heard it before and (2) I
believed it to be true.

3.  And all this brings me to the lab today.

4.  SSH connect to siesta.cs.wustl.edu as cs160, and make your own
directory under .www-docs/phptest.  In notepad, write a page that uses php
to echo the time and date, using $foo = system("date"); echo $foo.  Put
this on the server and point your browser to
www.cse.wustl.edu/~cs160/phptest and see if it works.

Now change it so that it prints the time/date in a red font.  Show yourself
that you can do this using echo "font color=red" or just by adding a
FONT tag.

5.  Remember split?  Of course you don't.  Try $pieces = split(' ',$foo),
and in fact, why not google help on "php split" and read the exact
specification.  It's good to learn to do this.

Can you print (or echo -- print, echo, and printf all work!) JUST the
time of day?  It's something like $pieces[3] or $pieces[4].

Now split the time of day into its components and just print the
number of seconds.

6.  Let's be dynamic.  GO straight to the URL php.net/if.  This is your
help page on the if statement in PHP.  Could any language be easier
at helping you learn it?????  I mean, you can say "php.net/if" faster
than you can type "www.google.com<ENTER>php if".  Truth.

I want your PHP to test whether the number of seconds is less than or
equal to 5.  If it is, give the page a green background and say "YOU ARE
LUCKY!" in a huge font.  Otherwise, nothing but "try again" in a little font.

7.  Now the form stuff.  Get a nice new notepad sheet and put three input
text fields on it, with a submit button.  Give them names like Moe, Curly,
and Bob.  DO YOU REMEMBER HOW TO do a form?  I'll help:

	FORM METHOD=get ACTION=target.php
	  LI	INPUT SIZE=10 NAME=moe		MOE
	  LI	INPUT SIZE=10 NAME=curly	CURLY
	  LI	INPUT SIZE=10 NAME=bob		BOB
	/FORM

although you should supply a submit button and some HTML delimiters.

Put this on the server as "stooges.html".

Enter input and submit the form and verify that it tries to find target.php?
followed by the data you entered.

8.  Ready?  Let's go easy at first.  Try write target.php to ignore the
input and echo "that's nice input, man".  Test it.

Now, let's print your first variable.  It should be 

	?php
	  echo $_GET["moe"] ;
	?

and unlike the unfortunate snafu in class, i tested it and it works.

Echo all three of the values passed to your php program.

Put them in different font sizes, then print the sum of the three,
assuming the inputs are numbers.  What does PHP do when it tries to
add three variables and one is not a number?

9.  There are a couple of examples I could not get to in class because
the conventions had changed.  Sysadmin! (Newman!)  Have a look at 
my logging example, 1117/l.txt.  That's an L, not a One.  (There is
a little lexical joke there, do you see it?)

You have to create a file in your directory called cgi.log and make it
readable and writeable to everyone.  You can do that with the properties
menu in SSH by right-clicking on the file.

The program opens the file for appending, giving a variable, $myfile,
something called a file handler.  From then on, you can put things
at the end of the file, and you can read it, each line going in
as an element in the $results array.

By the way, if you want to log the remote address, you need to change the
variable to $_SERVER["REMOTE_ADDR"] because of the sysadmin thing.

10.  Change your stooges.php so that it logs all three numbers
and their sum to a new file called stooges.log.

You now know about as much PHP as I do, and that's enough to
do all sorts of amazing things.  You might not realize it yet, but
before you leave, let me prove it to you:

Write a php script which prints "AND WE LOVE YOU TOO" in varying
font sizes, starting from small to large.  The loop you want is 
something like

        <?php
          $letters = split(':','A:N:D: :W:E: :L:O:V:E: :Y:O:U: :T:O:O') ;
          for ($i=0; $i<count($letters); $i++) 
            echo "<font style=font-size:$i>" . $letters[$i] ;
        ?>