Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to detect mobile users in Magento

Tags:

php

magento

What is the best way to detect if user is a mobile user in code level?

Admin can set regex based rules to detect and switch themes based on user agent but seems like this functionality is "protected" inside api and is not available as a set of methods every developer can use.

I understand that devs and designers should arrange their functionality in theme folders to be available/unavailable but this is rather hard requirement for extension providers as the regex rules can be somewhat loosely defined and admin does not have to specify if a theme is intended for mobile users

So maybe someone has a good method to sniff this out from core already (without implementing stuff over again to be public instead protected that is already available core/design_package)?

like image 827
Anton S Avatar asked Jan 30 '12 10:01

Anton S


1 Answers

How about this? Seems to work pretty well for me.

$isMobile = Zend_Http_UserAgent_Mobile::match(
    Mage::helper('core/http')->getHttpUserAgent(),
    $_SERVER
);

Though I haven't done enough research, maybe the wurfl adapter is more robust, per this thread.

like image 151
quickshiftin Avatar answered Sep 19 '22 23:09

quickshiftin