【问题标题】:Detecting splash page PHP file from non-mobile devices从非移动设备检测启动页面 PHP 文件
【发布时间】:2015-09-03 15:37:17
【问题描述】:

我正在尝试调用一个 php 文件,该文件仅在有人单击非 android 或 iOS 设备上的链接时才会打开。在我只有一条错误消息之前。

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');
    }
}

这是我最后的 else 语句的合适方法,我如何调用该 php 文件来显示启动错误页面?

【问题讨论】:

标签: php


【解决方案1】:

您可以通过以下方式将用户代理与preg_match 一起使用。

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');
     }
 }

这正是我从您的问题文本中得到的。您可能需要将其实现到您的脚本文件中或按照您想要的方式对其进行编辑。

【讨论】:

  • 那你建议如何调用 php 文件?
  • @BhoffDev 经过 6 分钟的工作,对你来说更清楚了。我希望。
猜你喜欢
  • 2010-09-06
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-21
  • 1970-01-01
  • 2012-10-11
相关资源
最近更新 更多