
SESSIONLESS NETWORKS 243
You can see a few PHP tags in the
HTML. These add the PHP variables to
the HTML. Next, you need some code
in the script to read the form. Add the
following near the beginning of the
program, after the global variables,
but before you open the socket to the
XPort:
8
//if a filled textbox was submitted, get the values:
if ((isset($_POST["ip"])) &&
(isset($_POST["port"])) &&
(isset($_POST["packetsToRead"]))) {
$ip = $_POST["ip"];
$port = $_POST["port"];
$packetsToRead = $_POST["packetsToRead"];
}
Figure 7-11
The final web page of the toxic report.
Add two new variables to the
beginning of the program, one to get
the time, and one to make the HTML
code simpler to write:
// $messageString is used to return messages for printing in the HTML:
$messageString = "No Sensor Reading Taken";
// Get the time and date:
$timeStamp = $date = date("m-d-Y H:i:s");
8
To use these two variables, change
the lines that average and print the
sensor reading like so. You’ll get a page
that looks like Figure 7-11.
8
// average the readings from all the packets to get a
// final sensor reading:
$totalAverage = averagePackets($packets);
// update the message for the HTML:
$messageString =
"Sensor Reading at: ". $timeStamp . ": " . $totalAverage;
Continued from opposite page.
size="15" maxlength="15">
Por