Mobile Browser Detection

Hi Mike, even though there is already a good browser detection ( extension that solution of yours is quite good; love its simplicity. Thanks for sharing buddy.

Oh, didn’t notice. It’s actually based on Chris Schuld’s Browser class i’ve mentioned above. Maybe i should give it a try, too.

Thanks for pointing that out, Antonio.

I’ve used Mike’s suggestion above to detect mobile devices and display a mobile version, and it works great. However, I was wondering if there is a way to give mobile users the ability to switch back and forth between the mobile version and the full desktop version. I’ve tried several different things but nothing seems to work.


You can put a button or a link that say "full version/mobile version" and that calls your page with a special parameter like "dev=d" or "dev=m"… then in your code you just check for this parameter before detecting the mobile browser… and if its there put it in session

Thanks for your reply. That’s what I’ve been trying to do, but I can’t get it to work correctly. Instead of changing $this->layout like Mike did above, I created a mobile theme and changed themes with

Yii::app()->theme = 'mobile';

That worked for the initial theme change to the mobile version, but I haven’t been able to get it to switch back based on a user’s input. I’m thinking that the issue is passing parameters to the init() function. Is it even possible to pass parameters to the init() function, or am I going about this the wrong way?


Google / Bing “Responsive Webdesign” - it’s the craze these days.

HTML5 Boilerplate is ready for it, but it’s basically using media queries with a js fallback for older browsers.

There’s no need to maintain a separate mobile version IMO.

Unless, of course, you are targeting older mobiles (WAP).

I found a nice site with lots of mobile detection code and stumbled across this forum post at the same time. I can’t post a link since this is my first forum post but I’m a big fan of Yii and will certainly write my own extension/behavior/whatever. Search “detect mobile browsers open source mobile phone detection” on Google and as of this post that will be the first result. =P


I’ve been on both sides of this, making use of WURFL and writing my own implementation using known types. The first is the most complete and accurate way i’ve found but WURFL really can be a pain to setup. The second method is much easier but will need constant upgrading to keep up to date. I also find these implementations tend to miss out the ipad but on the whole idea of that and more pad devices hitting the market, detected them will be the new goal.

Detect features, not devices.

That how jQuery’s new implementation of browser detection works so that way can work too. However it isn’t always down to features and support being the reason for detection, a lot of people just want different versions of their sites for mobiles and ipad so a mixture of the both is needed.

The big issue when using media queries is that your mobile browser will still load a bunch of resources you don’t need, then hide them using conditional formatting.

You base your opinion on a single article?

The answer is: no.

And: yes.

No, because if you design for mobile first and use the right tools, lesser browsers will only receive what they make use of.

Yes, because we still haven’t figured out exactly how to do this just yet.

There’s a lot of research going on, so please don’t make the mistake of thinking you can find the answer by performing a simple Google search…

Brad Frost is one you need to study:

And this web dev advent calendar also has some really great articles on it:

I have been reading into mobile solutions on and off over the past year, but didn’t come across anything convincing yet.

Until the pioneers of the web have figured out how to do this right, I’m sticking with maintaining a separate mobile version (using a different layout or theme to offer the same content). I cannot recommend the use of media queries just for the sake of maintainability.

Ofcourse, we all look forward to more optimized solutions ;)

I am going to try this one’s code for mobile browser detection:

[color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]This article [/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]explains[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]very well how to[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]detect[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]mobile browsers[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color].

Your link talks about switching to a different theme but nothing on detecting mobile browsers?

Anyways, I turned my used method into an extension:

Session lose only @mobile devices:

hi, im facing an issue when im taking my app in mobile device ie losing session.i have a login feature in app that works fine but after login all of my session values are idea why.

Which mobile device and which browser? How exactly does your ‘login feature’ work? Does it overwrite session variables?

I like this approach:

Hello community am looking for a way where when my application is loaded on a mobile device to redirect the user to a certain page eg search page and not the normal index page.Which is the best approach?