Created
October 25, 2014 20:42
-
-
Save zaneclaes/cbd5df8526393e88f78d to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// 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 ? $device : 'OSX'; | |
$params['os_version'] = $v ? $v : ''; | |
$params['timestamp'] = time(); | |
// Save $params in a database somewhere... | |
return $clients[$device]; | |
} | |
// | |
$from = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; | |
$from = explode('?', $from); | |
$from = sizeof($from) >= 2 ? $from[1] : ''; | |
$qps = explode('&', $from); | |
$params = array(); | |
foreach($qps as $qp) { | |
$parts = explode('=', $qp); | |
if(sizeof($parts)>=2 && strpos($parts[0], 'utm_')===0) { | |
$params[substr($parts[0],4)] = $parts[1]; | |
} | |
} | |
header('location: '. createReferral($params)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment