0

I am trying to call a php file that opens only if someone clicks a link from a non android or iOS device. Before I only had an error message.

if(isset($_GET['appId'])){

$products = getAppDownloadLinks(mysql_string($_GET['appId']));
//do something with this information
if( $iPod || $iPhone || $iPad){
    header('Location: '.$products['ios']);
    exit;
}
else if($Android){
    header('Location: '.$products['android']);
    exit;
}
else{
    //we're not a mobile device.
    $html = file_get_contents('mobileSplash.php');
    }
}

Is this an appropriate approach for my final else statement, how do I call that php file to display the splash error page?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
PokéDev
  • 163
  • 4
  • 14
  • You should check this link: http://stackoverflow.com/questions/14646918/get-specific-device-information :) – Asier Paz Sep 03 '15 at 15:48
  • I personally would use a library like http://mobiledetect.net/ (in case the algorithm was made from scratch) – ka_lin Sep 03 '15 at 15:50

1 Answers1

0

You can use the User Agent with preg_match in the following way.

if(isset($_GET['appId']))
{

     $products = getAppDownloadLinks(mysql_string($_GET['appId']));
     $apple = (preg_match($ua, "/(iPhone|iPod|iPad)/") === 1);
     $android = (preg_match($ua, "/(Android)/") === 1);
     //do something with this information
     if($apple)
     {
         header('Location: '.$products['ios']);
         exit;
     }
     elseif($android)
     {
         header('Location: '.$products['android']);
         exit;
     } else
     {
         //we're not a mobile device.
         $html = file_get_contents('mobileSplash.php');
     }
 }

This is just what I got out of your Question's Text. You may need to implement it into your Script File or edit it the way you want to have it.

Sainan
  • 1,274
  • 2
  • 19
  • 32