Understanding MochiAds Publisher Bridge – Part 2
This is the second part of Understanding MochiAds Publisher Bridge.
In the first step I showed you how to configure a cross-domain policy file, calling the javascript and send the results to a webpage.
Now it’s time to prevent cheating.
As you can see, it’s very easy to send some POST variables to a webpage, and it’s even easier to do it when you know the name of such webpage… and in our case you can know it simply looking at the html.
If you look at the html of the page containing Mazeroll, it’s clear the name of the page I send the POST array to is postscores.php.
So we have to prevent cheating.
That’s why in your MochiAds publisher settings page you’ll find a secret key that can be used to authenticate the score data sent from the Bridge to your server.
In your POST variables you can find one called signature.
This is an MD5 hash of the POST vars + your secret key. So the MD5 hash of the POST vars + your secret key and the signature must match.
In order to use this for authentication, you have to follow these steps:
- Populate an array of all parameter names as keys and their values
- Remove out the signature parameter
- Sort the array alphabetically by the key name
- Turn the array into a url encoded string
- Append your secret key
- Compute the MD5 hash with the string
- compare your MD5 hash with the signature parameter sent by the Bridge
So I prepared this little script that does the job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php // your secret key $key="xxxxxxxxxxxxxxxxxxxxxxxxxx"; // initializing an empty string - not strictly necessary $string = ""; // ordering the associative POST array by keys ksort($_POST); // loop scanning through all POST array foreach($_POST as $varname => $varvalue){ // if the key is not "signature" then append key and url encoded values to the string if($varname!="signature"){ $string.=$varname."=".rawurlencode($varvalue)."&"; } } // removing the last character (a "&"") $string = substr($string,0,strlen($string)-1); // appeding the secret key to the string $string.= $key; // comparing the md5 encryption of the string with the "signature" variable if(md5($string)==$_POST[signature]){ // it's a valid submission! } ?> |
Now you can check for valid submissions, next time I’ll show you what to do with them
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.
5 Responses to “Understanding MochiAds Publisher Bridge – Part 2”
Leave a Reply
Trackbacks
-
Understanding MochiAds Publisher Bridge – Part 3 : Emanuele Feronato on
August 24th, 2009 6:34 pm
[...] part 2 we saw how to prevent [...]
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Monetize your Flash games with GamesChart
- Box2D Flash game creation tutorial – part 1
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.87/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)

(7 votes, average: 4.29 out of 5)





Wow, it’s been a while since you’ve published a PHP tutorial. Looking forward to more!
Moar plz noaw!
:)
I think I have become a fan for life… :)
At least I bug report and donate!!!
Hello , ahh . . . i guess it is because of my stupidity but i cant figure out where to put this script on my site ,, should it be in the postscores.php or what ??