Created
November 6, 2009 05:35
-
-
Save jkells/227752 to your computer and use it in GitHub Desktop.
Example of a simple php script to tell an iphone app which add network to use dynamically.
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
| <?php | |
| $app = $_GET['APP']; | |
| $version = $_GET['VERSION']; | |
| // Map each application / version to a chance table | |
| $appTbl = array( | |
| "REMOTEKITTENFREE"=>array( | |
| "1.1" => array( | |
| array(0.1, "MOBCLIX"), | |
| array(0.9, "ADMOB") | |
| ) | |
| ) | |
| ); | |
| $chanceTbl = $appTbl[$app][$version]; | |
| $sum = 0; | |
| $dice = rand(0, 1); | |
| foreach($chanceTbl as $network){ | |
| $sum += $network[0]; | |
| if($dice <= $sum){ | |
| $resultNet = $network[1]; | |
| break; | |
| } | |
| } | |
| $response = array("NETWORK"=>$resultNet); | |
| header('Content-type: application/json'); | |
| echo json_encode($response); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment