Created
June 18, 2012 12:09
-
-
Save sandeepshetty/2948073 to your computer and use it in GitHub Desktop.
Shopify incoming request verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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