Jump to content

Polling a server, downloading data, uploading confirmation.


enveetee

Recommended Posts

Looking for some guidance on this...

 

I have two applications, A windows desktop application written in VB6/VB.NET and my new (and learning) PHP/MYSQL app.

 

I am mirroring records between them. Records can be added to both systems and I synchronise them.

 

I am currently dealing with downloading the PHP/MYSQL records to my desktop and was wondering if I was going about it in the right way.

 

This is how I have designed it...

I have a common form which deals with three actions (POLL, DOWNLOAD and CONFIRM) using POST. I can return the number of records to be downloaded (using the POLL) paramater, the actual record (using a DOWNLOAD parameter along with a record ID) and finally a CONFIRM parameter to mark the MYSQL record as having been downloaded and is in the desktop database. I am ECHO'ing out values from the PHP form which is being received by the desktop component.

 

This does work, but was wondering if the way I was doing it is ok - it seems too simple which scares me!

 

Comments/advice/bullet-between-the-eyes - please

 

 

here's the code if you are interested...

<?php


require_once('../includes/cs_functions.php');
require_once('../includes/cs_password.php');
require_once('../includes/meekrodb.2.3.class.php');
require_once('../classes/cUser.php');
FN_MeekroDBSetup();


//Call as POLL first to return id's of records needed to be downloaded TAB separated
//Whitelist the POST values into WhiteListParameter array
$WLP = allowed_post_params(['cs_name', 'cs_password', 'cs_mode', 'cs_id', 'cs_serialno', 'cs_downloadtime']);


//Declare the user class for user name and password validation later
$cUser = new clsUser;


//These are debug settings so form can be executed in Netbeans
$WLP['cs_name'] = 'Admin';
$WLP['cs_password'] = 'a';
$WLP['cs_mode'] = 'POLL';
$WLP['cs_mode'] = 'DOWNLOAD';
$WLP['cs_mode'] = 'CONFIRM';




//Validate user, returns NULL if user not valid
$cUser = FN_Validate_User($WLP['cs_name'], $WLP['cs_password'], TRUE);


if ($cUser == NULL) {


} else {




//Detect mode POLL, CONFIRM, DOWNLOAD
switch ($WLP['cs_mode']) {


case "POLL":
//Check if any records to be downloaded and return a TAB delimited list of record ID's
$resultsArray = db::query("SELECT * FROM bk WHERE bkwebbooking=%s AND bkwebbooking_downloadedtime=%s", '1', NULL);
$tmp = '';
foreach ($resultsArray as $row) {
$tmp = $tmp . $row['id'] . chr(9);
}


//Loose trailing TAB
$tmp = FN_Shorten($tmp, 1);
break;


case "DOWNLOAD":
//Return the record for import into desktop system
$resultsArray = db::query("SELECT * FROM bk WHERE id=%s", $WLP['cs_id'], NULL);
$tmp = '';
foreach ($resultsArray as $row) {
$tmp = $tmp . $row['id'] . chr(9) . $row['bkaccount'] . $row['bkservice'];
}
break;
case "CONFIRM":
//Update MYSQL record with time and serial number from desktop system $cs_serialno, $cs_downloadtime




default:
$tmp = 'Call with POLL or DOWNLOAD or CONFIRM';
break;
}


echo $tmp;
}
Edited by mac_gyver
fixed code font size and added code tags around posted code
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.