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?

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

5
  • if this not work for anyone. try to remove browser cache if you have already open website in mobile.
    – Rocky Sinh
    Dec 4, 2016 at 14:10
  • It will not show results if resize browser, only work in actual devices.
    – Sourav
    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
    Nov 13, 2017 at 14:46
  • @Kul I want to use your method. Where would you recommend adding this condition? Sep 23, 2018 at 10:22
  • you can include it in block/helper method and then use it in template if required
    – Kul
    Sep 24, 2018 at 8:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.