A simple iOS / Android traffic splitter in PHP

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.

    $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”);

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.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *