cstevensjr Posted March 18, 2015 Posted March 18, 2015 The Title of the referenced topic has been edited, per your request
FrancisChung Posted February 23, 2017 Posted February 23, 2017 I've just installed it on a PW 3.x site. It seems to detect Desktop correctly but I think it's returning an empty string for mobile. Haven't tested for Tablet but for my purposes I can live with this as I'm only interested in whether it's Desktop or not. Will update if it can't detect Desktops correctly. if (wire(config)->mobileDetect->deviceType<>'desktop') { .... }
FrancisChung Posted March 5, 2017 Posted March 5, 2017 (edited) I just wanted to update saying the module doesn't work. The problem is that the actual PHP module it depends on, mobiledetect.php is using $_SERVER['HTTP_USER_AGENT'] which is an outdated way of detecting devices from the server. It failed on Safari where it couldn't distinguish whether you were using it from the Desktop or a mobile device. (You could argue PHP is probably not the way to go, compared to JS but that's another post ) I must have tried every PHP based solution out there in the last couple of weeks. The only thing that has worked for me is UserAgentInfo. I'm posting an example here, in case some one wants to update this module function IsMobile() { $ua = UserAgentInfoPeer::getMy(); $mobile = $ua->isMobile(); return $mobile; } P/S You will need to add a reference to this class (You may need to change the path to suit your code structure) require_once(__DIR__.'/../vendor/UserAgentInfo/UserAgentInfoPeer.class.php'); and then you may need to configure UserAgentInfoConfig class if the caching mechanism (Redis by default) is not what you want. Just change the CACHE_CLASS_NAME to the class you want. //const CACHE_CLASS_NAME = 'UaiCachePhpredis'; //Not installed locally //const CACHE_CLASS_NAME = 'UaiCacheMemcached'; //Not installed on Provider //const CACHE_CLASS_NAME = 'UaiCacheAPC'; //Not installed on Provider const CACHE_CLASS_NAME = 'UaiCacheDebug'; FYI I had to go for the non cached version (UaiCacheDebug) because of the hosting solution we currently have (i.e. el cheapo solution) Edited March 5, 2017 by FrancisChung More info
justb3a Posted March 9, 2017 Author Posted March 9, 2017 @FrancisChung Thanks a lot for your feedback and hints. The collaborators of the detection library are working on a new release. Quote Still working on 3.0.0 branch to provide you with device detection! We're really excited on this one! We would like to speed this up, but life and family gets in the way As soon as the release has been published, I'll update the module.
ngrmm Posted September 26, 2017 Posted September 26, 2017 On 9.3.2017 at 3:03 PM, justb3a said: @FrancisChung Thanks a lot for your feedback and hints. The collaborators of the detection library are working on a new release. As soon as the release has been published, I'll update the module. hmm … module didn't work (pw 3) but when i use the detection library and it works // Include and instantiate the class. require_once 'Mobile_Detect.php'; $detect = new Mobile_Detect; // Any mobile device (phones or tablets). if ( $detect->isMobile() ) { }
abdus Posted September 26, 2017 Posted September 26, 2017 10 minutes ago, ngrmm said: hmm … module didn't work Probably because the module is outdated by 2 years. Last commit was at Sep 7, 2015 1
justb3a Posted January 7, 2018 Author Posted January 7, 2018 I just updated and tested the module, it should work correctly with PW3. 2
neophron Posted September 19, 2018 Posted September 19, 2018 Hi, first, thanks for this cool module! I have a question: Is there a way to detect the browser and show it by name? Like firefox, safari or chrome?
Rob Coldwell Posted December 11, 2018 Posted December 11, 2018 Hi. Nice module! Exactly what I was looking for to make my main nav-bar conditional (if desktop, hovering drops-down my menu but clicking goes to page, if tablet etc., clicking just drops-down). Perfect! Thanks. echo "<li class='dropdown'><a href='". ($config->mobileDetect->deviceType == 'desktop' ? $child->url : '#') ."' data-hover='dropdown'>{$child->title}<b class='caret'></b></a>";
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now