title: How to detect if the user has the mobile application from a website and open the app
body: <p>My website is not mobile responsive, but i have a mobile app for both <strong>Android</strong> and <strong>iOS</strong>. When people visit my website using one of these two platforms, I would like to direct them to my mobile app.</p>
  
  <p>If they already have my mobile app,  I would like it to auto open that app, otherwise I'd like the person to be redirected to the Google Play store or Apple AppStore to download the mobile app. </p>
  
  <p>I don't know how to do that.  Please help me with tips on how to do this.</p>
  
  <pre><code>&lt;?php
  class UserInfo{
  
      private static function get_user_agent() {
          return  $_SERVER['HTTP_USER_AGENT'];
      }
  
      public static function get_os() {
  
          $user_agent = self::get_user_agent();
          $os_platform    =   "Unknown OS Platform";
          $os_array       =   array(
              '/windows nt 10/i'      =&gt;  'Windows 10',
              '/windows nt 6.3/i'     =&gt;  'Windows 8.1',
              '/windows nt 6.2/i'     =&gt;  'Windows 8',
              '/windows nt 6.1/i'     =&gt;  'Windows 7',
              '/windows nt 6.0/i'     =&gt;  'Windows Vista',
              '/windows nt 5.2/i'     =&gt;  'Windows Server 2003/XP x64',
              '/windows nt 5.1/i'     =&gt;  'Windows XP',
              '/windows xp/i'         =&gt;  'Windows XP',
              '/windows nt 5.0/i'     =&gt;  'Windows 2000',
              '/windows me/i'         =&gt;  'Windows ME',
              '/win98/i'              =&gt;  'Windows 98',
              '/win95/i'              =&gt;  'Windows 95',
              '/win16/i'              =&gt;  'Windows 3.11',
              '/macintosh|mac os x/i' =&gt;  'Mac OS X',
              '/mac_powerpc/i'        =&gt;  'Mac OS 9',
              '/linux/i'              =&gt;  'Linux',
              '/ubuntu/i'             =&gt;  'Ubuntu',
              '/iphone/i'             =&gt;  'iPhone',
              '/ipod/i'               =&gt;  'iPod',
              '/ipad/i'               =&gt;  'iPad',
              '/android/i'            =&gt;  'Android',
              '/blackberry/i'         =&gt;  'BlackBerry',
              '/webos/i'              =&gt;  'Mobile'
          );
  
          foreach ($os_array as $regex =&gt; $value) {
              if (preg_match($regex, $user_agent)) {
                  $os_platform    =   $value;
              }
          }   
          return $os_platform;
      }
  ?&gt;
  </code></pre>