Skip to content

Instantly share code, notes, and snippets.

@jkells
Created November 6, 2009 05:35
Show Gist options
  • Save jkells/227752 to your computer and use it in GitHub Desktop.
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.
<?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