pref home next
day8: write web integration
Here is the PHP program
<html><head>
<title> control page
</title>
</head>
<br><br><br><br><br><br>
<center>
<b> Control page </b><br>
<br><br>
<a href="control.php?toggle=5">check status</a><br><br>
</center><br><br>
<?php
show_source
("control.php");
$STAT_FILE =
"/home/eddo/programming/stat.txt";
$FIFO_FILE = "/home/eddo/programming/MYFIFO"
;
if (!$toggle){
if (file_exists(
$STAT_FILE)) {
// En: Open, read, and close file.
echo "<br><br><
table width=\"300\">";
echo
"<tr><td> port nr </td><td> status </td><td> action </td></tr>"
;
echo "<tr><td>
</td><td> </td><td> </td> </tr>"
;
$fp =
fopen("$STAT_FILE"
, "r");
$buffer = fgets
($fp,
4096);
if (
$buffer==1)
$stat1="<font
color=\"green\"><b>on</b></font>";
else
$stat1=
"<font color=\"red\"><b>off</b></font>";
$buffer =
fgets($fp,
4096);
if ($buffer
==1)
$stat2="<font
color=\"green\"><b>on</b></font>";
else
$stat2="<font
color=\"red\"><b>off</b></font>";
$buffer = fgets
($fp,
4096);
if (
$buffer==1) $stat3="<font color=\"green\"><b>on</b></font>";
else $stat3="<font color=\"red\"><b>off</b></font>";
$buffer = fgets($fp
, 4096);
if ($buffer==1) $stat4="<font color=\"green\"><b>on</b></font>";
else $stat4="<font color=\"red\"><b>off</b></font>";
fclose($fp);
} else {
echo "Can't find file, check '\$file' var...<BR>";
$stat1 = "off";
$stat2 = "off";
$stat3 = "off";
$stat4 = "off";
}
echo "<tr><td> 1 </td><td> $stat1 </td><td><a href=\"control.php?toggle=1
\">toggle</a></td></tr> \n";
echo "<tr><td> 2 </td><td> $stat2 </td><td><a href=\"control.php?toggle=2\">toggle</a></td></tr> \n";
echo "<tr><td> 3 </td><td> $stat3 </td><td><a href=\"control.php?toggle=3\">toggle</a></td></tr> \n"
;
echo "<tr><td> 4 </td><td> $stat4 </td><td><a href=\"control.php?toggle=4\">toggle</a></td></tr> \n";
echo "</table>";
}
if($toggle){
if (file_exists(
$FIFO_FILE)) {
// En: Open, read, and close file.
$fp = fopen("$FIFO_FILE",
"w");
fputs($fp, $toggle);
fclose($fp);
echo "toggled port $toggle <br><br>waiting 2 sec..<br>";
echo"<a href=\"javascript:history.back()\">go back</a><br><br> ";
echo "<meta http-equiv=\"refresh\" content=\"02; url=control.php\"> ";
}
}
?>
</html>
see here an example...
pref home next
day8: write web integration