Skip to content

Instantly share code, notes, and snippets.

@brunokruse
Created March 18, 2014 17:51
Show Gist options
  • Save brunokruse/9625480 to your computer and use it in GitHub Desktop.
Save brunokruse/9625480 to your computer and use it in GitHub Desktop.
private function __get_id($qr_code) {
if (empty($qr_code)) {
return false;
}
$arrBarCode = explode(',', $qr_code);
if (empty($arrBarCode[1])) {
return false;
}
$beginning = substr($arrBarCode[1], 0, 16);
$end = substr($arrBarCode[1], -16);
$id = str_replace(array($beginning, $end), '', $arrBarCode[1]);
if (empty($id) || !is_numeric($id)) {
return false;
}
$qrOptions = Configure::read('Campaign.QR');
$md5 = md5(urlencode(trim($arrBarCode[0])) . ',' . $id . ',' . $qrOptions['secret']);
if ($beginning . $end !== $md5) {
return false;
}
return $id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment