Created
February 17, 2013 13:34
-
-
Save rmruano/4971509 to your computer and use it in GitHub Desktop.
Miniplay API: Parameters validation snippet (PHP)
This file contains hidden or 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
| /* 1. Decode all get parameters */ | |
| foreach ($_GET as $key=>$value) | |
| $_GET[$key] = urldecode($value); /* 1. May not be needed in your language */ | |
| /* 2. Check signature */ | |
| if ($_GET['mini_signature'] != signParameters("YOUR_API_KEY",$_GET)) { | |
| die("The 'mp_*' parameters signature is invalid"); | |
| } else { | |
| echo "The 'mp_*' parameters signature is valid!"; | |
| } | |
| /* 3. Helper function definition, yeah, it will look so good inside a class :) */ | |
| /** | |
| * Signs an array of mp_* parameters, | |
| * @param string $apiKey | |
| * @param array $parameters | |
| * @return string signature | |
| */ | |
| function signParameters($apiKey, array $parameters) { | |
| foreach ($parameters as $key=>$value) { | |
| if (substr($key,0,3)!="mp_") unset($parameters[$key]); /* Exclude parameter from validation */ | |
| $parameters[$key] = (string)$value; /* Cast to string not needed in PHP but other languages may need it. */ | |
| } | |
| return md5($apiKey.json_encode($parameters)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment