I am testing with Codeigniter3.0.6 on User agent as below function then I try to testing IPhone, and Chrome inspect device mode but I got only number 1. I want to check if I view this website in Mobile phone it will echo number 2 if in PC browser echo number1 if can't detect browser show 0.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Main_Controller extends MY_Controller
{
public $data = array();
public function __construct()
{
parent::__construct();
var_dump($this->CheckDevices());
exit();
$this->data['deviceType'] = $this->CheckDevices();
if ($this->data['deviceType'] == 1) {
$this->set_navigation();
}
elseif ($this->data['deviceType'] == 2) {
retu false;
}elseif($this->data['deviceType'] == 0){
retu false;
}
}
private function CheckDevices()
{
$this->load->library('user_agent');
$agent = '';
if ($this->agent->is_browser()) {
$agent = 1;
} elseif ($this->agent->is_mobile()) {
$agent = 2;
} else {
$agent = 0;
}
retu $agent;
}
private function set_navigation()
{
$this->load->library('session');
$this->load->library("nav_libs");
retu $this->data['menus'] = $this->nav_libs->navigation();
}
}
?>
