PHP scripts must be located in htdocs The file extension is .php Code is protected by ... ?> A field entitled "something" produces a variable "$something" that contains the value brought in by the field (this is the CGI convention, e.g., in Perl with CGI.pm we would have said that a field entitled "something" can have its value accessed through the following sequence: use CGI; $q = new CGI; $something = $q->param('something'); In PHP we get this without any effort.) So we start from this combination of files (in htdocs/0218): UW PICO(tm) 4.10 File: form.html
UW PICO(tm) 4.10 File: one.php Well echo $who ?> you will be echo $age + 1 ?> years old next year. And we can combine the two: UW PICO(tm) 4.10 File: one.php if ($who) { ?> Well echo $who ?> you will be echo $age + 1 ?> years old next year.} else { ?> Please use the form below to enter and submit your data.
} ?>
And we have two examples: 1. Simple counter with two buttons state client side hidden fields. UW PICO(tm) 4.10 File: two.php // retrieve state gives us $balance, $times for free if ($times) { if ($direction == "up") { $balance += 1; } else { $balance -= 1; } $times += 1; } else { // initialize state $times = 1; $balance = 0; } ?>2. Same program with server-side state: session_start(); // retrieve state gives us $balance, $times for free if ($times) { if ($direction == "up") { $balance += 1; } else { $balance -= 1; } $times += 1; } else { // initialize state session_register("times"); session_register("balance"); $times = 1; $balance = 0; } ?>
The session is in: -bash-3.2$ cd apache/ -bash-3.2$ cd phpsessions/ -bash-3.2$ ls -bash-3.2$ ls -l total 8 -rw------- 1 dgerman faculty 22 Feb 18 12:28 sess_04afcc6d592c96e51c378cf785876648 -bash-3.2$ cat sess_04afcc6d592c96e51c378cf785876648 times|i:3;balance|i:2;-bash-3.2$ cat sess_04afcc6d592c96e51c378cf785876648 times|i:7;balance|i:-2;-bash-3.2$