ecshop判断其他页面手机访问跳转到ECTouch对应手机版页面

ecshop其他页面包含商品详情页、商品分类页、团购页、优惠活动页、积分商城,判断如果是手机访问跳转到ECTouch手机版对应页面方法
首先在ecshop根目录下打开includes/lib_main.php文件,添加一个函数function pc_to_mobile(),代码如下:
/**
 * ECSHOP 实现商品详情页、商品分类页、团购页、优惠活动页、积分商城
 * 判断是否手机访问跳转到ECTouch手机版对应页面方法
 * $Author: ecshop.cx
 * @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)
    {
        /*
         * 如果你绑定了手机版域名 https://www.ecshop.cx/mobile 为 https://m.ecshop.cx
         * 那么 $mobile_url = https://m.ecshop.cx
         */
        $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 .'/?c='.$filename.'&a=index&'.$_SERVER["QUERY_STRING"];
                }
            }
            /* 处理无分类的 */
            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();

本文原创地址:https://www.ecshopok.com/article-412.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

文章评论

暂无评论,来发表一个吧

发表 取消
充值有惊喜 ECSHOP插件网微信客服edait_cn