185 visitas
PHP function to check the mochimedia bridge signature
A lot of people is having problems to check the signature that Mochi Media uses to authenticate the score data sent from the Bridge (see official docs). This small PHP function (from my flash games portal) is simple, very easy to use and understand and works perfectly:
PHP
- /**
- * Calculates the signature according to the Mochi security protocol
- *
- * @param array $parameters Paramters received by $_POST
- * @return string The Mochi signature
- */
- public static function calculateMochiSignature($parameters)
- {
- //sort $parameters alphabetically by the key
- $queryString = '';
- // Concatenate all parameters according to the format defined in the documentation
- foreach($parameters as $k => $v)
- {
- if( $k != 'signature')
- {
- }
- }
- // Remove the last '&'
- }
Then, you can check if you have been passed the correct signature like this:
PHP
- calculateMochiSignature($_POST) == $_POST['signature'];
Enviado por miguelSantirso hace 3 months — modificado por última vez hace less than a minute