duanqiao2006 2013-12-26 20:02
浏览 50
已采纳

移动重定向循环

I want mobile users to be redirected to a specific page on my WP site. I am trying to use this script, but it's causing an infinite loop. Can the mobile page be on the same domain or do I have to create a sub-domain for the mobile page?

Thanks!

function is_mobile(){
    $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
    $regex_match.="htc|dopod|blazer|netfront|helio|hos in|huawei|novarra|CoolPad|webos|techfaith|palmsour ce|";
    $regex_match.="blackberry|alcatel|amoi|ktouch|nexi an|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|ma ui|";  
    $regex_match.="symbian|smartphone|midp|wap|phone|w indows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
    $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mob i|opera\*mini|320x320|240x320|176x220";
    $regex_match.=")/i";    

    return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}

switch($_GET['mode'])
{
case 'mobile':
    $mode = "mobile";
    break;
case 'desktop':
    $mode = "desktop";
    break;
default:
    $mode = is_mobile() ? "mobile" : "desktop";
    break;
}

if ($mode == "mobile")
{
    header ("Location: http://example.com/mobile");
    return;
  • 写回答

1条回答 默认 最新

  • doujian1050 2013-12-26 20:11
    关注

    add a check before issuing the location header that you're not currently on a mobile page (e.g. by checking $_SERVER['REQUEST_URI']or via some variable that you set only on mobile page), or don't include this redirect script when you're on a mobile page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大