ecshop其他页面判断是智能手机访问也跳转到ECTouch对应手机版页面[有修正]

来源:互联网 发布:java socket.flush 编辑:程序博客网 时间:2024/06/08 12:17

ecshop 其他页面(商品详情页、商品分类页、团购页、优惠活动页、积分商城) 判断如果是智能手机访问跳转到ECTouch1.0手机版对应页面 方法

 

首先在ecshop 根目录下 includes/lib_main.php  添加一个函数function pc_to_mobile()

/** * ecshop 实现其他页面(商品详情页、商品分类页、团购页、优惠活动页、积分商城) * 判断如果是智能手机访问的话 跳转到ECTouch1.0手机版对应页面 方法 * * @access  public */function pc_to_mobile(){    //判断是否是手机访问    $is_mobile = false;    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);    $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";     if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))    {        $is_mobile = true;    }     /* 判断是否重写,取得文件名 */    $cur_url = basename(PHP_SELF);    if (intval($GLOBALS['_CFG']['rewrite'])){        $filename = strpos($cur_url,'-') ? substr($cur_url, 0, strpos($cur_url,'-')) : substr($cur_url, 0, -4);    }else{        $filename = substr($cur_url, 0, -4);    }     if($is_mobile){        /*         * 如果你绑定了手机版域名 http://www.abc.com/mobile 为 http://m.abc.com         * 那么 $mobile_url = http://m.abc.com         */        $mobile_url = $GLOBALS['ecs']->url().'mobile';         /* 根据文件名分别处理中间的部分 */        if ($filename != 'index')        {            /* 处理有分类的 */            if (in_array($filename, array('category', 'goods', 'brand')))            {                /* 商品分类或商品 */                if ('category' == $filename || 'goods' == $filename || 'brand' == $filename)                {                    $Loaction = $mobile_url .$_SERVER['REQUEST_URI'];                }            }            /* 处理无分类的 */            else            {                /* 团购 */                if ('group_buy' == $filename)                {                    if(!empty($_GET['id'])){                        $Loaction = $mobile_url .'/?c=groupbuy&a=info&id='.$_GET['id'];                    }else{                        $Loaction = $mobile_url .'/?c=groupbuy';                    }                }                /* 拍卖 */                elseif ('auction' == $filename)                {                    if(!empty($_GET['id'])){                        $Loaction = $mobile_url .'/?c=auction&a=info&id='.$_GET['id'];                    }else{                        $Loaction = $mobile_url .'/?c=auction';                    }                }                /* 夺宝 */                elseif ('snatch' == $filename)                {                    if(!empty($_GET['id'])){                        $Loaction = $mobile_url .'/?c=snatch&a=info&id='.$_GET['id'];                    }else{                        $Loaction = $mobile_url .'/?c=snatch';                    }                }                /* 批发 */                elseif ('wholesale' == $filename)                {                    if(!empty($_GET['id'])){                        $Loaction = $mobile_url .'/?c=wholesale&a=info&id='.$_GET['id'];                    }else{                        $Loaction = $mobile_url .'/?c=wholesale';                    }                }                /* 积分兑换 */                elseif ('exchange' == $filename)                {                    if(!empty($_GET['id'])){                        $Loaction = $mobile_url .'/?c=exchange&a=exchange_goods&gid='.$_GET['id'];                    }else{                        $Loaction = $mobile_url .'/?c=exchange';                    }                }                /* 优惠活动 */                elseif ('activity' == $filename)                {                    $Loaction = $mobile_url .'/?c=activity';                }             }            /* ecshop跳转到手机对应页面 */            if (!empty($Loaction)){                ecs_header("Location: $Loaction");                exit;            }        }     } }
然后 在 ecshop 根目录下 includes/init.php 大概129行 商店关闭 判断代码 之后 添加(商店关闭的话 也不需要跳转了)
pc_to_mobile();


以上修改 适用于网站程序是ecshop2.7.3版本与手机版ECTouch1.0且没有经过二次开发。

0 0