Re: [PHP] Detect and Redirect Mobile Users
Ford, Mike wrote: > (someone else wrote:) > > $browser = get_browser(null, TRUE); > > if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice'] == > > TRUE)) { > > $isMobile = TRUE; > > } > > else { > > = FALSE; Mike's remarks below notwithstanding, I think something fell off here. > > } > > unset($browser); > > Argh!, Argh!, Argh! -- two of my pet hates in one snippet! Tell us how you really feel, Mike. :)) > Comparing something ==TRUE is almost always unnecessary, and > absolutely always when it's used as an element of a Boolean > expression: if x evaluates to TRUE, x==TRUE is also TRUE, and if it > evaluates to FALSE x==TRUE is also FALSE, so the comparison is > unnecessary, redundant and wasteful. Just use x. The only time I'd be looking at whether content of $somearray['somekey'] == TRUE is when it's possible that it may contain something other than TRUE or FALSE, and somehow my code *cares* whether it does. In this case, we do not, your rant holds. > And why use an if test on a Boolean value to see if it's TRUE or > FALSE, just so you can assign TRUE or FALSE?? Since the thing you're > testing has the value you want in the first place, just flipping > assign it! This is most egregious. > $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice']; This would even be a case where I'd opt for: $isMobile = @$browser['ismobiledevice']; since if it *isn't* set, it's still falsy, with the rather strong caveat of don't use @ indiscriminantly. > Cheers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Detect and Redirect Mobile Users
> -Original Message- > From: Dead Letter.Office [mailto:dead.letter.off...@isam.co.nz] > Sent: 14 June 2013 05:22 > To: php-general@lists.php.net > > http://php.net/manual/en/misc.configuration.php#ini.browscap > http://tempdownloads.browserscap.com/ > > $browser = get_browser(null, TRUE); > if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice'] > == TRUE)) { > $isMobile = TRUE; > } > else { > = FALSE; > } > unset($browser); Argh!, Argh!, Argh! -- two of my pet hates in one snippet! Comparing something ==TRUE is almost always unnecessary, and absolutely always when it's used as an element of a Boolean expression: if x evaluates to TRUE, x==TRUE is also TRUE, and if it evaluates to FALSE x==TRUE is also FALSE, so the comparison is unnecessary, redundant and wasteful. Just use x. And why use an if test on a Boolean value to see if it's TRUE or FALSE, just so you can assign TRUE or FALSE?? Since the thing you're testing has the value you want in the first place, just flipping assign it! $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice']; Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom (FROM 21st JUNE: Leslie Silver Building 403a, City Campus, Woodhouse Lane, LS1 3ES) E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Detect and Redirect Mobile Users
http://www.answershat.com/questions/352/How-to-get-rid-of-spam-mail-in-my-mailbox On 14 June 2013 09:28, Chirag Vekariya wrote: > Hi, > Post your question to http://answershat.com > > On Thu, Jun 13, 2013 at 4:49 AM, dealTek wrote: > >> Hi all, >> >> I'm curious of a simple, common, universal way to detect a mobile user so >> I can redirect them to a mobile directory... >> >> What is best for this: Javascript - CSS - PHP? >> >> I think for my purposes if I can detect screen size or mobile browser >> agent - that would be good enough for what I need right now. >> >> Thanks in advance - Dave >> >> >> -- >> Thanks, >> Dave - DealTek >> deal...@gmail.com >> [db-3] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > *Thanks & Regards, > Chirag Vekariya. > +91-87582 45922* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Detect and Redirect Mobile Users
Hi, Post your question to http://answershat.com On Thu, Jun 13, 2013 at 4:49 AM, dealTek wrote: > Hi all, > > I'm curious of a simple, common, universal way to detect a mobile user so > I can redirect them to a mobile directory... > > What is best for this: Javascript - CSS - PHP? > > I think for my purposes if I can detect screen size or mobile browser > agent - that would be good enough for what I need right now. > > Thanks in advance - Dave > > > -- > Thanks, > Dave - DealTek > deal...@gmail.com > [db-3] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- *Thanks & Regards, Chirag Vekariya. +91-87582 45922*
Re: [PHP] Detect and Redirect Mobile Users
On Jun 13, 2013, at 15:31, Camille Hodoul wrote: > Hello, > > I stumbled upon this the other day : > http://mobiledetect.net/ > I haven't tried it yet, since I have my own small user agent parser when I > need it, but it may help you if it's a pure php solution you're looking for. > > Have a nice day > > > 2013/6/13 dealTek > >> Hi all, >> >> I'm curious of a simple, common, universal way to detect a mobile user so >> I can redirect them to a mobile directory... >> >> What is best for this: Javascript - CSS - PHP? >> >> I think for my purposes if I can detect screen size or mobile browser >> agent - that would be good enough for what I need right now. >> >> Thanks in advance - Dave >> >> >> -- >> Thanks, >> Dave - DealTek >> deal...@gmail.com >> [db-3] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > Camille Hodoul > http://camille-hodoul.com/ Some time ago, I tested php-mobile-detect and detectmobilebrowsers.com, taking the (old) wurfl database (as a reference with a bit less than 15.000 mobile devices). Tests came out as follows: php-mobile-detect: 7 seconds in 15.000 devices, 70% accuracy detectmobilebrowsers.com: 0.6 seconds in 15.000 devices, 93,5% accuracy The post I made is in spanish, but could serve as a reference: http://blog.unreal4u.com/2012/10/detectar-facilmente-un-dispositivo-movil/ As for the OP, I think that the best way would be PHP, because you can do a lot more, like not even redirecting the user but rather just load the mobile site directly, setting a session value if desktop version is forced or not. This way, any links would also be interchangeable, making it easier for you to implement specific functionality such as "send link through email" and other related things. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Detect and Redirect Mobile Users
http://php.net/manual/en/misc.configuration.php#ini.browscap http://tempdownloads.browserscap.com/ $browser = get_browser(null, TRUE); if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice'] == TRUE)) { $isMobile = TRUE; } else { $isMobile = FALSE; } unset($browser); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Detect and Redirect Mobile Users
Hello, I stumbled upon this the other day : http://mobiledetect.net/ I haven't tried it yet, since I have my own small user agent parser when I need it, but it may help you if it's a pure php solution you're looking for. Have a nice day 2013/6/13 dealTek > Hi all, > > I'm curious of a simple, common, universal way to detect a mobile user so > I can redirect them to a mobile directory... > > What is best for this: Javascript - CSS - PHP? > > I think for my purposes if I can detect screen size or mobile browser > agent - that would be good enough for what I need right now. > > Thanks in advance - Dave > > > -- > Thanks, > Dave - DealTek > deal...@gmail.com > [db-3] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Camille Hodoul http://camille-hodoul.com/
Re: [PHP] Detect and Redirect Mobile Users
On Thu, Jun 13, 2013 at 3:20 PM, Matijn Woudt wrote: > > > > On Thu, Jun 13, 2013 at 3:17 AM, Paul M Foster wrote: > >> On Wed, Jun 12, 2013 at 04:19:50PM -0700, dealTek wrote: >> >> > Hi all, >> > >> > I'm curious of a simple, common, universal way to detect a mobile user >> so I can redirect them to a mobile directory... >> > >> > What is best for this: Javascript - CSS - PHP? >> > >> > I think for my purposes if I can detect screen size or mobile browser >> agent - that would be good enough for what I need right now. >> >> This is not really a PHP question. I understand your asking it, though. >> Does anyone know of a better list or whatever for generic web designer >> questions? >> >> To your question, there are two problems: 1) Looking for a browser >> signature is a needle/haystack proposition, and the haystack is >> enormous, and it gets bigger every time a new phone/tablet model comes >> out; 2) Screen size used to be a good indicator, but as I feared when >> people first started using screen resolution as the main indicator, the >> screens on mobile devices have become progressively more and more >> capable. Some of them are better than many desktops I've seen. >> >> So I'd be interested in the answer to the question myself. >> >> Paul >> >> > HI, > > Even though the list gets bigger, there aren't that many mobile operating > systems. Any Android device will have Android in it's user agent, and > iPhone as iPhone in the User Agent string. > If you want to check for tablets, you can check for iPad specifically (it > is in the user agent), and for Android, I believe that mobile devices have > 'Mobile' in the user agent string, and tablets don't. > > Then there is ofcourse the small 1 percent or so Blackberry & WP users, > which can probably be detected easily too with their user agent. > > Cheers, > > Matijn > I forgot to mention, in PHP the user agent string is in $_SERVER['HTTP_USER_AGENT'], and in javascript you can find it in navigator.userAgent. Where you want to redirect, it's up to you. If you want it to do on first attempt, better go with PHP so you can use Header("Location: ...") to redirect the user immediately so the user won't notice he is being redirected.
Re: [PHP] Detect and Redirect Mobile Users
On Thu, Jun 13, 2013 at 3:17 AM, Paul M Foster wrote: > On Wed, Jun 12, 2013 at 04:19:50PM -0700, dealTek wrote: > > > Hi all, > > > > I'm curious of a simple, common, universal way to detect a mobile user > so I can redirect them to a mobile directory... > > > > What is best for this: Javascript - CSS - PHP? > > > > I think for my purposes if I can detect screen size or mobile browser > agent - that would be good enough for what I need right now. > > This is not really a PHP question. I understand your asking it, though. > Does anyone know of a better list or whatever for generic web designer > questions? > > To your question, there are two problems: 1) Looking for a browser > signature is a needle/haystack proposition, and the haystack is > enormous, and it gets bigger every time a new phone/tablet model comes > out; 2) Screen size used to be a good indicator, but as I feared when > people first started using screen resolution as the main indicator, the > screens on mobile devices have become progressively more and more > capable. Some of them are better than many desktops I've seen. > > So I'd be interested in the answer to the question myself. > > Paul > > HI, Even though the list gets bigger, there aren't that many mobile operating systems. Any Android device will have Android in it's user agent, and iPhone as iPhone in the User Agent string. If you want to check for tablets, you can check for iPad specifically (it is in the user agent), and for Android, I believe that mobile devices have 'Mobile' in the user agent string, and tablets don't. Then there is ofcourse the small 1 percent or so Blackberry & WP users, which can probably be detected easily too with their user agent. Cheers, Matijn
Re: [PHP] Detect and Redirect Mobile Users
Hi, On Thu, Jun 13, 2013 at 1:19 AM, dealTek wrote: > Hi all, > > I'm curious of a simple, common, universal way to detect a mobile user so > I can redirect them to a mobile directory... > > What is best for this: Javascript - CSS - PHP? > > I think for my purposes if I can detect screen size or mobile browser > agent - that would be good enough for what I need right now. > > Thanks in advance - Dave > > In my personnal experiences, I've used varnish (for caching mainly) and for mobile redirection purpose. A few line in your vcl configuration and there you go. You can even put a rules to indicate that if there is a GET parameter or a cookie, you don't redirect the user. It means that you can simply add a link on your mobile website to send the user back on the desktop website if he prefers. I like this approach as it is directly on your first frontend (or load balancer) and you don't even need to load you php app to redirect the user. Regards, -- bacardi55 (bacardi55.org)
Re: [PHP] Detect and Redirect Mobile Users
Hi, It might be a good solution for your problem: http://detectmobilebrowsers.com/ You can find php, js, apache, etc scripts for your problem. Regards, Peter Tihanyi http://systream.hu 2013.06.13. 1:19 keltezéssel, dealTek írta: Hi all, I'm curious of a simple, common, universal way to detect a mobile user so I can redirect them to a mobile directory... What is best for this: Javascript - CSS - PHP? I think for my purposes if I can detect screen size or mobile browser agent - that would be good enough for what I need right now. Thanks in advance - Dave -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Detect and Redirect Mobile Users
On Wed, Jun 12, 2013 at 04:19:50PM -0700, dealTek wrote: > Hi all, > > I'm curious of a simple, common, universal way to detect a mobile user so I > can redirect them to a mobile directory... > > What is best for this: Javascript - CSS - PHP? > > I think for my purposes if I can detect screen size or mobile browser agent - > that would be good enough for what I need right now. This is not really a PHP question. I understand your asking it, though. Does anyone know of a better list or whatever for generic web designer questions? To your question, there are two problems: 1) Looking for a browser signature is a needle/haystack proposition, and the haystack is enormous, and it gets bigger every time a new phone/tablet model comes out; 2) Screen size used to be a good indicator, but as I feared when people first started using screen resolution as the main indicator, the screens on mobile devices have become progressively more and more capable. Some of them are better than many desktops I've seen. So I'd be interested in the answer to the question myself. Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Detect and Redirect Mobile Users
Hi all, I'm curious of a simple, common, universal way to detect a mobile user so I can redirect them to a mobile directory... What is best for this: Javascript - CSS - PHP? I think for my purposes if I can detect screen size or mobile browser agent - that would be good enough for what I need right now. Thanks in advance - Dave -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php