I would like to have the updater check against my database to see if a user is eligible for updates. To do this I've created a script on my server that checks the user's "install_date" and adds a year to it. If that value is less than the current date, then the user is not eligible for updates any longer. I've added the URL to the "License Check URL" when building the updater and have uploaded the update file to my server, but it's not working.
Here is my code, can someone tell me what I'm doing wrong?
Code: Select all
<?php
// connect to db
$dbhost = 'localhost';
$dbname = ****';
$dbuser = '****';
$dbpass = '****';
$dbconn = null;
connect_to_db();
// get all required parameters
$license_id = get_parameter('licenseid');
if ($license_id === null || !is_numeric($license_id)) {
response(200, "603\nExpired");
}
// get data from db for provided serial number
$filter = "`camera_sn` = '$license_id' AND `install_date` > DATE_SUB(CURDATE(), INTERVAL 1 YEAR)";
$row = get_row_from_db('customer_no, install_date', 'customers', $filter);
if (is_null($row)) {
response(200, "603\nExpired");
} else {
mysqli_query($dbconn, "update `customers` set `install_date` = CURDATE() WHERE `customer_no`='{$row['customer_no']}'");
response(200, "601\nOK");
}
die;
////////////////////////////////////////////////////////////////////////////////
// implementation
function response($code, $msg = null)
{
header("HTTP/1.1 $code", true);
if ($msg !== null)
echo $msg;
die;
}
function get_parameter($name)
{
global $dbconn;
if (!isset($_POST[$name]))
return null;
$value = mysqli_real_escape_string($dbconn, trim($_POST[$name]));
if ($value === '')
return null;
return $value;
}
function connect_to_db()
{
global $dbconn;
if ($dbconn !== null)
return;
global $dbhost, $dbname, $dbuser, $dbpass;
$dbconn = mysqli_connect($dbhost, $dbuser, $dbpass) or response(500);
mysqli_query($dbconn, "set names utf8;");
mysqli_query($dbconn, "set character set utf8;");
mysqli_query($dbconn, "set collation_connection = 'utf8_general_ci';");
mysqli_query($dbconn, "use `$dbname`;");
}
function get_row_from_db($columns, $table, $filter)
{
global $dbconn;
if ($dbconn === null)
response(500);
$query = "select $columns from $table where $filter";
$res = mysqli_query($dbconn, $query);
if ($res === false)
response(500);
$row = mysqli_fetch_assoc($res);
mysqli_free_result($res);
return $row;
}
FOLLOW US
Get the latest news in Application Packaging