【问题标题】:Codeigniter user_agent not workingCodeigniter user_agent 不工作
【发布时间】:2016-02-02 09:41:25
【问题描述】:

如 codeigniter 的用户文档中所述,我已使用以下内容检测移动设备、机器人和桌面设备。

     if ($this->agent->is_mobile()) {
           // This is a mobile device
        $data['is_mobile'] = true;
        $this->load->view('mobile/template/header');
        $this->load->view('mobile/template/imageDiv', $data);
        $this->load->view('mobile/template/footer');       
        } else if ($this->agent->is_robot()) {
            // This is a robot, treat it like a mobile device so that our content is indexed
        $data['is_mobile'] = true;
        $this->load->view('mobile/template/header');
        $this->load->view('mobile/template/imageDiv', $data);
        $this->load->view('mobile/template/footer');       

        } else {
        $data['is_mobile'] = false;
        $this->load->view('template/header');

        $this->load->view('login/loginOnHover', $data);
        $this->load->view('template/imageDiv', $data);
        $this->load->view('template/booking_track', $data);
        $this->load->view('template/recent_hotels', $data);
        $this->load->view('template/easybooking');
        $this->load->view('template/features');
        $this->load->view('template/stepsApi', $data);
        $this->load->view('template/footer');       
    }

它几乎适用于所有移动设备,但对于 google nexus 系列、黑莓 PlayBook 和 Ipads,它显示桌面视图。 我该如何解决?

【问题讨论】:

  • 你试过了吗? $this->agent->is_mobile('iPad')
  • @RaviHirani 我也检查过,但对我也不起作用。

标签: php android codeigniter mobile


【解决方案1】:

试试这个方法:-

在应用程序/库/MY_User_agent.php 中:

class MY_User_agent extends CI_User_agent {

    public function __construct()
    {
        parent::__construct();
    }

    public function is_ipad()
    {
        return (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
          // You can add other checks for other tablets
    }
}

这样检查:-

    $this->load->library('user_agent');

    ($this->agent->is_ipad() === TRUE) ? $is_ipad = "Yes" : $is_ipad = "No";

    echo "Using ipad: $is_ipad";

【讨论】:

    猜你喜欢
    • 2014-06-26
    • 2014-04-15
    • 2012-12-02
    • 2018-06-16
    • 2016-03-01
    • 1970-01-01
    • 2012-04-29
    • 2013-05-09
    • 2014-05-21
    相关资源
    最近更新 更多