Code Igniter - Best Browser Detection Method

I want to disable all browsers of a certain age on their own page. What is the best method to do this? Perhaps some JS in the header that is wrapped:

<!--[if lte IE 7 ]> <script type="text/javascript"> window.location = "/unsupported-browser/"; </script> <![endif]--> 

Should I not send to the browser: http://example.com/unsupported-browser/ , where I have a basic controller and a view for processing it? It's simple?

+2
source share
2 answers

Do it instead of php. Use the user_agent class and redirect to this page.

But more importantly, why don't you allow IE users to access your site? Is this related to CSS or something else?

The code:

 $this->load->helper('url'); $this->load->library('user_agent'); if ($this->agent->browser() == 'Internet Explorer' and $this->agent->version() <= 7) redirect('/unsupported-browser'); 

Edit:

As mentioned; if you want this all over the site, run it in MY_Controller and don't forget to add $this->uri->segment(1) != 'unsupported-browser' as an additional condition to avoid loop redirection.

+15
source

Download the library from http://mobiledetect.net

Put Mobile_Detect.php in the "library"

inside the main controller

 public function index() { $this -> load -> library('Mobile_Detect'); $detect = new Mobile_Detect(); if ($detect->is('Chrome') || $detect->is('iOS')) { // whatever you wanna do here. } } 

Find documentation at http://dwij.co.in/mobile-os-detection-in-php-codeigniter

+2
source

All Articles