dongruoqiong9017 2012-03-08 20:43
浏览 49

如果用户浏览到子域,PHP将重定向到移动版本

Scenario: I have a website set up with a php 'Mobile Detect' function. If a mobile device IS detected OR version=mobile (which sets a cookie), they are shown (via php) the mobile version of the page. If a mobile device is NOT detected, OR if the version=full (which sets a cookie), they are shown (via php) the Full version of the site. This all takes place on example.com of my domain.

I want to allow users to force the mobile version of the site (in case they have previously set the version Cookie) if they visit m.example.com.

Is there a way to redirect m.example.com to www.example.com AND set the version=mobile ? I tried doing this with my DNS settings, using a URL redirect from the 'm' subdomain to www.example.com/index.php?version=mobile which DOES work for the URL, however when the page is shown, even though the ?version=mobile is in the URL, my PHP 'Mobile Detect' does not pick up on this, and still renders the Full version of the page.

EDIT :: FYI I am on a Linux Server.

  • 写回答

3条回答 默认 最新

  • dongshen9058 2012-03-08 20:48
    关注

    This is the php code, it is more efficiently if you use htaccess for this

    $iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
    $palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
    $berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
    $ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
    
    if ($iphone || $android || $palmpre || $ipod || $berry == true) 
    { 
       echo "<script>window.location='http://m.site.com'</script>";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)