Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created October 25, 2014 20:27
Show Gist options
  • Save zaneclaes/8da41041373d11f78081 to your computer and use it in GitHub Desktop.
Save zaneclaes/8da41041373d11f78081 to your computer and use it in GitHub Desktop.
//
// Detect's the user's mobile client
// If it is a matched client, creates a referral item in parse and returns a redirect URL for the AppStore
//
function createReferral($params = array()) {
require_once '../cms/Mobile_Detect.php';
$detect = new Mobile_Detect;
$ios_url = 'https://itunes.apple.com/us/app/aftermath-pvp-guilds-strategy/id702615597?ls=1&mt=8';
$clients = array('iPhone'=>$ios_url,
'iPod'=>$ios_url,
'iPad'=>$ios_url);
$device = null;
foreach($clients as $client => $url) {
if($detect->is($client)) {
$device = $client;
break;
}
}
if(!$device) {
return $ios_url;
}
$v = $detect->version($device);
$params['ip'] = $_SERVER['REMOTE_ADDR'];
$params['device'] = $device;
$params['os_version'] = $v ? $v : '';
$params['timestamp'] = time();
// Store $params as an object into a database, somewhere...
return $clients[$device];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment