P
P
pcdesign2016-07-03 13:53:47
PHP
pcdesign, 2016-07-03 13:53:47

How to detect in Magento that the site was accessed from a mobile device?

Magento ver. 1.9.0.1
Tried like this:

$ua = Mage::helper('core/http')->getHttpUserAgent();
if ( Zend_Http_UserAgent_Mobile::match($ua,  $_SERVER )){
        echo '<p>This is mobile</p>'; 
}

But, something is not working.
Whichever browser it is, always returns true and always writes "This is mobile".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Gerasimenko, 2016-07-03
@pcdesign

This is more a PHP question than a Magento question. It's already been answered on SO:
stackoverflow.com/questions/5335237/how-to-check-i...
MobileESP-based solution suggested: blog.mobileesp.com
Here's another one from SO:
stackoverflow.com/questions/4117555/ simplest-way-t...
And this is special. extension with helper for Magento:
https://www.magentocommerce.com/magento-connect/ca...
Googled for the phrase php 5 detect mobile
Your solution is also on SO:
stackoverflow.com/questions/5541171/how-to- handle-...
Why doesn't this option work? This can be found by analyzing the contents of the $ua variable.and the logic of the Zend_Http_UserAgent_Mobile::match() method. What values ​​get into the $ua variable in your case?

Thanks for the help. Understood. The code in the topic is working. This is a purely Magenta joke related to caching. I dragged the code to another place, everything worked, where there is no hard caching.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question