James Bachini

A simple iOS / Android traffic splitter in PHP

The 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.

TIP: This uses a 301 redirect however you can do any type of programmatic variation based on the user agent.

    $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.

Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.