A simple iOS / Android traffic splitter in PHP

0
834

phoneThe following basic PHP code will split traffic by device with iOS traffic going to the first out link, Android to the second and leftovers to the third.

<?php
    $ua = strtolower($_SERVER[‘HTTP_USER_AGENT’]);
    if (strpos($ua,’iphone’) !== false || strpos($ua,’ipod’) !== false || strpos($ua,’ipad’) !== false) {
        $out = ‘https://iosoutlink.com/’;
    } elseif (strpos($ua,’android’) !== false) {
        $out = ‘https://androidoutlink.com’;
    } else {
        $out = ‘https://allotherstuff.com’;
    }
    header(“HTTP/1.1 301 Moved Permanently”);
    header(“Location: $out”);
    exit();
?>

You can copy and paste this into a myfile.php text file for example. Upload it to your server and any traffic you point to it http://mydomain/myfile.php will be redirected to the right app store or offer.

LEAVE A REPLY

Please enter your comment!
Please enter your name here