Skip to content

Instantly share code, notes, and snippets.

@acrosman
Last active April 3, 2023 06:27
Show Gist options
  • Save acrosman/ff85c0a180caa0bc0dc2d83bbd9e7a80 to your computer and use it in GitHub Desktop.
Save acrosman/ff85c0a180caa0bc0dc2d83bbd9e7a80 to your computer and use it in GitHub Desktop.
A PHP function to sign dynamic parameters for FormAssembly
<?php
function prepareFormAssemblyQueryString(array $parameters, $salt, $expire_timeout) {
$parts = [];
$signString = '';
foreach($parameters as $key => $value) {
$signString .= $key . $value;
$parts[] = rawurlencode($key) . '=' . rawurlencode($value);
}
$expireTime = time() + $expire_timeout;
$signString .= 'expire' . (string)$expireTime;
// hmach the signature string
$hash = hash_hmac('sha256', $signString, $salt, TRUE);
$sig = rawurlencode(base64_encode($hash));
$parts[] = 'signature=' . $sig;
$parts[] = 'expire=' . (string)$expireTime;
$queryString = implode('&', $parts);
return $queryString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment