Instructions
36
Server side
Usually the HTTP request would point to a dedicated web server page with
scripting capabilities. For example we assume a page called www.server.com/
multilogger.php. On the server side this page would contain some scripting
that decodes the data, checks its contents and store the data into a data
storage. Other webpages can be used to report measurements from this
storage. This document is not intended to be a scripting manual; we refer to
themanyhelpavailableelsewhere.PleaselookatthePHPhelptopic‘varia-
blesfromoutsidePHP’forexample.Inordertoprovideaquickstartweshow
how variables can be evaluated on a PHP page:
PHP EXAMPLE
<?php
// multilogger.php
//needs6arguments,separatedby‘&’:
// The message would be: abcdef&&$d&&$t&&$i&&$v
//argument0=‘password’(abcdef)
// argument 1 = $d date // argument 2 = $t time
// argument 3 = $i sensor id
/ argument 4 = $v sensor value
$args = explode (“&”, $QUERY_STRING );
$nargs = count($args);
if ($nargs != 5)
{
die();
}
if ($args[0] != “abcdef”)
{
die();
}
$date = urldecode($args[1]) ;
$time = urldecode($args[2]) ;
$device = urldecode($args[3]);
$temperature = urldecode($args[4]);
$date=str_replace(“’”,““,$date);
$time=str_replace(“’”,““,$time);
$device=str_replace(“’”,““,$device);
$temperature=str_replace(“’”,““,$temperature);
// log it
$db=mysql_connect(‘server’,‘user’,‘password’);
$result=mysql_select_db(‘database_name’,$db);
$result=mysql_query(“deletefromtemperaturewhere(device=’$device’)”);
$result = mysql_query(“INSERT INTO temperature (logdate, logtime, device, temperature)
VALUES(‘$date’,‘$time’,‘$device’,‘$temperature’)”,$db);
$result = mysql_close($db);
>?
E
N
G
L
I
S
H