Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Agent for Code Igniter not detecting mobile devices like Android or Blackberry #1347

Closed
reypm opened this issue May 10, 2012 · 1 comment

Comments

@reypm
Copy link

reypm commented May 10, 2012

I’m using CI UA library but if I navigate trough a BB device or a Android, I get always “Safari” as result. This is my code:
$this->load->library('user_agent');
if ($this->agent->is_browser()) {
$device = $this->agent->browser();
} elseif ($this->agent->is_mobile()) {
$device = $this->agent->mobile();
} else {
$device = "";
}

I test the UA returned by my browser and get this:
Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
And from my BB get this:
Mozilla/5.0 (Blackberry U;Blackberry 9300;en) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.00.668 Mobile Safari/534.8+
But UA class still saying for BB that it's Safari when is not.
The entire thread is here: http://codeigniter.com/forums/viewthread/217014/

@narfbg
Copy link
Contributor

narfbg commented May 11, 2012

Your logic is wrong ... Just because you're accessing the page from a mobile device, it doesn't mean that you're not using a browser. It's natural that is_browser() returns TRUE and since you're using elseif, your application never gets to the is_mobile() check, which works fine by itself.

@narfbg narfbg closed this as completed May 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants