I am working on Magento 1.9 and i want to check condition for mobile using php code how can i do this? can anybody help to figure out this?
-
You can use media query to make responsive.– KulCommented Dec 4, 2016 at 11:44
-
@Kul sorry but i want to put condition using php code to add class when page open in mobile device– Rocky SinhCommented Dec 4, 2016 at 11:46
-
Please check i have added answer hope it will help.– KulCommented Dec 4, 2016 at 11:50
Add a comment
|
1 Answer
You can use below condition . It's work for me for detect mobile device.
$isMobile = Zend_Http_UserAgent_Mobile::match(
Mage::helper('core/http')->getHttpUserAgent(),
$_SERVER
);
Note: If you are testing in desktop or laptop by Responsive design view. It will not work. Its only work in mobile.
-
if this not work for anyone. try to remove browser cache if you have already open website in mobile. Commented Dec 4, 2016 at 14:10
-
It will not show results if resize browser, only work in actual devices.– SouravCommented Nov 13, 2017 at 4:12
-
@Paarth Yes. Its php side code. it will used to add php conditon or class while load page. if you resize page it will not work. you have to used Js code to achieve it.– KulCommented Nov 13, 2017 at 14:46
-
@Kul I want to use your method. Where would you recommend adding this condition? Commented Sep 23, 2018 at 10:22
-
you can include it in block/helper method and then use it in template if required– KulCommented Sep 24, 2018 at 8:36