0

I'm trying to find a simple way of showing different content dependant on the operating system. To put this into context, it's sort of like an app store, which would show android apps for people using android devices and windows apps for windows users etc.

Carla Dessi
  • 9,086
  • 9
  • 39
  • 53
  • http://stackoverflow.com/questions/4104607/easiest-way-os-detection-with-php – Seshu Vinay Mar 11 '14 at 10:02
  • possible duplicate of [Determine if operating system is Mac](http://stackoverflow.com/questions/15845928/determine-if-operating-system-is-mac) – super-qua Mar 11 '14 at 10:05

2 Answers2

0

Try this:

<?php
    // android
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
        header('Location: https://play.google.com/store/apps/details?id=YOUR_BUNDLE_ID');
        exit();
    }
    // ipad
    $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
    // iphone/ipod
    if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
    {
        header('Location: https://itunes.apple.com/YOUR_LINKG_TO_APPLE_STORE');
        exit();
    }
    header('Location: http://www.default.com');
?>
EnriMR
  • 3,924
  • 5
  • 39
  • 59
0

What you can do is use 51Degrees device detector. It is perfect for mobile device detection but also works when it comes to desktop OS detection.

Follow the 4-step set up at 51Degrees PHP Getting Started.

To identify Operating System:
$_51d['PlatformName'] gives you the name of the operating system.
$_51d['PlatformVendor'] gives you the manufacturer (i.e Apple for OsX)
$_51d['PlatformVersion'] gives you the version of detected OS.

Mike
  • 144
  • 8