1

I have a CI Bonfire installation and I don't know where can I detect if a user is viewing the page on a mobile device or desktop PC? Is this done directly in front controller application/core/Base_Controller.php ?

If user is on desktop PC I need to redirect them to specific page inside my installation. And this must be detectable all over my website in all controllers.

Matic-C
  • 783
  • 2
  • 11
  • 16

2 Answers2

1

Load User agent Lib

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

use this function to detect is mobile

$mobile=$this->agent->is_mobile();
if($mobile){
  //your code
}
Kundan Picker
  • 81
  • 1
  • 2
0

You can simply do the following check in your root file (Beginning).

$isMobile = (bool)preg_match('#\b(ip(hone|od|ad)|android|opera m(ob|in)i|windows (phone|ce)|blackberry|tablet'.
                    '|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'.
                    '|mobile|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i', $_SERVER['HTTP_USER_AGENT'] );

if(isMobile())
    header("Location: http://m.site.com/");
Asik
  • 7,967
  • 4
  • 28
  • 34
  • do you mean the `index.php` in my root? Because index there is titled "Welcome to CI-Bonfire" and only reads "Some things have changed since the last version,.." I doubt this is the controller – Matic-C Nov 13 '14 at 13:57
  • Could you please post your current URL that from where you want to redirect? – Asik Nov 13 '14 at 14:01