Skip to content

Instantly share code, notes, and snippets.

@sandeepshetty
Created June 18, 2012 12:09
Show Gist options
  • Save sandeepshetty/2948073 to your computer and use it in GitHub Desktop.
Save sandeepshetty/2948073 to your computer and use it in GitHub Desktop.
Shopify incoming request verification
<?php
// All requests/redirects from Shopify include a signature parameter that can be used to verify the origin of the request.
function is_valid_request($query_params, $shared_secret)
{
$seconds_in_a_day = 24 * 60 * 60;
$older_than_a_day = $query_params['timestamp'] < (time() - $seconds_in_a_day);
if ($older_than_a_day) return false;
$signature = $query_params['signature'];
unset($query_params['signature']);
foreach ($query_params as $key=>$val) $params[] = "$key=$val";
sort($params);
return (md5($shared_secret.implode('', $params)) === $signature);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment