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?
Kul
1,8075 gold badges30 silver badges54 bronze badges
-
You can use media query to make responsive.Kul– Kul2016年12月04日 11:44:58 +00:00Commented 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 deviceRocky Sinh– Rocky Sinh2016年12月04日 11:46:20 +00:00Commented Dec 4, 2016 at 11:46
-
Please check i have added answer hope it will help.Kul– Kul2016年12月04日 11:50:58 +00:00Commented Dec 4, 2016 at 11:50
1 Answer 1
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.
answered Dec 4, 2016 at 11:49
Kul
1,8075 gold badges30 silver badges54 bronze badges
-
if this not work for anyone. try to remove browser cache if you have already open website in mobile.Rocky Sinh– Rocky Sinh2016年12月04日 14:10:25 +00:00Commented Dec 4, 2016 at 14:10
-
It will not show results if resize browser, only work in actual devices.Sourav– Sourav2017年11月13日 04:12:51 +00:00Commented 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.Kul– Kul2017年11月13日 14:46:13 +00:00Commented Nov 13, 2017 at 14:46
-
@Kul I want to use your method. Where would you recommend adding this condition?Konstantin Patroev– Konstantin Patroev2018年09月23日 10:22:59 +00:00Commented Sep 23, 2018 at 10:22
-
you can include it in block/helper method and then use it in template if requiredKul– Kul2018年09月24日 08:36:33 +00:00Commented Sep 24, 2018 at 8:36
default