diff --git a/README.md b/README.md index 6bfe3b2..b60e827 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ You will need an Apache web server set up to run PHP scripts and a MySQL databas ##BrightAuthor -The hearbeat-demo project shows a simple example of how to use the heartbeart plugin. Add it as a plugin under Files->Presentation Properties->Autorun. Then from a timer - or any action anywhere - you can 'Send' a plugin message. Whatever message text you use will be inserted as the 'event' string that goes into the database. DO NOT USE SPACES OR PUNCTUATION in that string - it can confuse things. Use a string like "timeout" or "button press" or something. This will allow you to have many different events trigger the 'heartbeat' and can track that in the database. +The hearbeat-demo project shows a simple example of how to use the heartbeart plugin. Add it as a plugin under Files->Presentation Properties->Autorun. Then from a timer - or any action anywhere - you can 'Send' a plugin message. Whatever message text you use will be inserted as the 'event' string that goes into the database. DO NOT USE SPACES OR PUNCTUATION in that string - it can confuse things. Use a string like "timeout" or "button_press" or something. This will allow you to have many different events trigger the 'heartbeat' and can track that in the database. You will need to create a user variable called "heartbeat_url" and set it to the URL of the PHP script on your server. You can also create a user variable called "heartbeat_tag" and put text there that you want to use to help make database queries. diff --git a/heartbeat.php b/heartbeat.php index 6873824..5232e87 100644 --- a/heartbeat.php +++ b/heartbeat.php @@ -8,25 +8,36 @@ $event = $_GET['event']; $ext_ip = $_SERVER['REMOTE_ADDR']; -$link = mysql_connect('localhost', 'REPLACE_USERNAME', 'REPLACE_PASSWORD'); -if (!$link) { - die('Not connected : ' . mysql_error()); -} +$mysqli = new mysqli('localhost', 'REPLACE_USERNAME', 'REPLACE_PASSWORD', 'brightsign'); -$db_selected = mysql_select_db('brightsign', $link); -if (!$db_selected) { - die ('Can\'t use foo : ' . mysql_error()); +/* Check Connection */ +if ($mysqli->connect_errno) { + printf("Connect failed: %s\n", $mysqli->connect_error); + exit(); } $sql1 = "DELETE FROM heartbeats WHERE snum='$serial';"; -$result1 = mysql_query($sql1) or die(mysql_error()); +if (!$mysqli->query($sql1)){ + printf("Error deleting from heartbeats: %s\n", $mysqli->error); + /* close connection */ + $mysqli->close(); + exit(); +} if ($tag=="") $tag="none"; if ($event=="") $event="none"; $sql2 = "INSERT INTO heartbeats (snum,version,fw,int_ip,ext_ip,tag,event) VALUES ('$serial','$version','$fw','$int_ip','$ext_ip','$tag','$event');"; -$result2 = mysql_query($sql2) or die(mysql_error()); +if (!$mysqli->query($sql2)){ + printf("Error inserting into heartbeats: %s\n", $mysqli->error); + /* close connection */ + $mysqli->close(); + exit(); +} + +/* close connection */ +$mysqli->close(); exit(header("Status: 200 OK"));