1

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
asked Dec 4, 2016 at 11:40
3
  • You can use media query to make responsive. Commented 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 Commented Dec 4, 2016 at 11:46
  • Please check i have added answer hope it will help. Commented Dec 4, 2016 at 11:50

1 Answer 1

5

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
5
  • 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. Commented 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. Commented 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 Commented Sep 24, 2018 at 8:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.