function _x($data) {
// Store the hash data from mobile.
$hash_from_mobile = end($data);
// Remove the hash data as it is not needed anymore.
array_pop($data);
// Serialize the data before in order to calculate the checksum value.
$query_string = serialize($data);
$hash = md5($query_string);
// Compare the checksum result to the hash value from mobile.
// If true this means the sync is completed successfully.
if ($hash_from_mobile == $hash) {
$sync_status = 'Completed';
// Check if the item ID exist on the database.
if (id_exist) {
// Update the record.
}
else {
// Record the item.
foreach ($data => $item) {
// Do the math here.
}
}
return drupal_json_output($sync_status);
}
// This means that the sync has failed or terminated somewhere before the data
// has been transfered to the receiving endpoint.
else {
$sync_status = 'Failed';
return $sync_status;
}
}
Created
January 18, 2017 00:48
-
-
Save iamstoick/fdb765496381ea9983fd7d0d8d9cec64 to your computer and use it in GitHub Desktop.
Checksum comparison from mobile to API endpoint
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment