Brandon, any chance you could share with us where you found the mobile detect PHP class?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
February 11, 2009 8:09pm
Subscribe [9]#16 / Mar 04, 2009 3:57pm
Brandon, any chance you could share with us where you found the mobile detect PHP class?
#17 / Mar 04, 2009 4:15pm
Brandon, any chance you could share with us where you found the mobile detect PHP class?
Not sure what Brandon used, but you can have a look at CodeIgniter’s User Agent class.
#18 / Mar 04, 2009 5:46pm
Ours is a custom PHP script loosely based on the tutorials below:
http://www.hand-interactive.com/resources/detect-mobile-php.htm
http://www.russellbeattie.com/blog/mobile-browser-detection-in-php
http://mobiforge.com/developing/story/lightweight-device-detection-php
http://www.brainhandles.com/2007/10/15/detecting-mobile-browsers/
and using the WURFL database (http://wurfl.sourceforge.net/)
Brandon, any chance you could share with us where you found the mobile detect PHP class?
Not sure what Brandon used, but you can have a look at CodeIgniter’s User Agent class.
How does EE determine a mobile user? Is it using a database such as WURFL or do you simply look for a certain set of strings in the user agent?
#19 / Mar 04, 2009 6:07pm
EE doesn’t have any mechanism for identifying mobile users - CodeIgniter’s code is open, though, so you can download and take a look. It’s pretty simple - we actually maintain our own list based on known user agents. It’s lightweight as you don’t need a full user agent string to be able to identify the platform.
#20 / Mar 23, 2009 12:14pm
Do not use the code you used above… I’ve already tried to tackle that to no avail. This is what I did after reading hte forums and it’s working AWESOMELY!
Create another template group called mobile and duplicate your real site… then strip out the html as you want it to look for mobile. Finally, stick this code in your index template and enable php (I’ve updated it for iphone and LG Dare):
<?php
/*
=====================================================
Mobile version detection
-----------------------------------------------------
compliments of <a href="http://www.buchfelder.biz/">http://www.buchfelder.biz/</a>
=====================================================
*/
$mobile = "http://yoursite.com/index.php/mobile/";
$text = $_SERVER['HTTP_USER_AGENT'];
$var[0] = 'LG';
$var[1] = 'Mozilla/3.0';
$var[2] = 'AvantGo';
$var[3] = 'ProxiNet';
$var[4] = 'Danger hiptop 1.0';
$var[5] = 'DoCoMo/';
$var[6] = 'Google CHTML Proxy/';
$var[7] = 'UP.Browser/';
$var[8] = 'SEMC-Browser/';
$var[9] = 'J-PHONE/';
$var[10] = 'PDXGW/';
$var[11] = 'ASTEL/';
$var[12] = 'Mozilla/1.22';
$var[13] = 'Handspring';
$var[14] = 'Windows CE';
$var[15] = 'PPC';
$var[16] = 'Mozilla/2.0';
$var[17] = 'Blazer/';
$var[18] = 'Palm';
$var[19] = 'WebPro/';
$var[20] = 'EPOC32-WTL/';
$var[21] = 'Tungsten';
$var[22] = 'Netfront/';
$var[23] = 'Mobile Content Viewer/';
$var[24] = 'PDA';
$var[25] = 'MMP/2.0';
$var[26] = 'Embedix/';
$var[27] = 'Qtopia/';
$var[28] = 'Xiino/';
$var[29] = 'BlackBerry';
$var[30] = 'Gecko/20031007';
$var[31] = 'MOT-';
$var[32] = 'UP.Link/';
$var[33] = 'Smartphone';
$var[34] = 'portalmmm/';
$var[35] = 'Nokia';
$var[36] = 'Symbian';
$var[37] = 'AppleWebKit/413';
$var[38] = 'UPG1 UP/';
$var[39] = 'RegKing';
$var[40] = 'STNC-WTL/';
$var[41] = 'J2ME';
$var[42] = 'Opera Mini/';
$var[43] = 'SEC-';
$var[44] = 'ReqwirelessWeb/';
$var[45] = 'AU-MIC/';
$var[46] = 'Sharp';
$var[47] = 'SIE-';
$var[48] = 'SonyEricsson';
$var[49] = 'Elaine/';
$var[50] = 'SAMSUNG-';
$var[51] = 'Panasonic';
$var[52] = 'Siemens';
$var[53] = 'Sony';
$var[54] = 'Verizon';
$var[55] = 'Cingular';
$var[56] = 'Sprint';
$var[57] = 'AT&T;';
$var[58] = 'Nextel';
$var[59] = 'Pocket PC';
$var[60] = 'T-Mobile';
$var[61] = 'Orange';
$var[62] = 'Casio';
$var[63] = 'HTC';
$var[64] = 'Motorola';
$var[65] = 'Samsung';
$var[66] = 'NEC';
$var[67] = 'AppleWebKit/420';
$var[68] = 'Version/3.0';
$var[69] = 'Mobile/1A543a';
$var[70] = 'Safari/419.3';
$var[71] = 'iPhone';
$result = count($var);
for ($i=0;$i<$result;$i++)
{
$ausg = stristr($text, $var[$i]);
if(strlen($ausg)>0)
{
header("location: $mobile");
exit;
}
}
?>#21 / Apr 16, 2009 9:03am
#22 / Sep 12, 2009 12:34pm
I am trying to do something like this,
{if ...}
some stuff
{if:else}
header("location: ".$url);exit;
{/if}the site seems to be redirecting regardless of the if condition (redirects even when the condition is true)
Any idea what I am doing wrong or how can I achieve such functionality!
#23 / Sep 12, 2009 2:01pm
Actually that code above works for me perfectly every time. Although I have noticed that just yesterday when I upgraded to IE8 that it redirects to the mobile version. I had to fix that for IE8 Beta. The user agent string for IE8 is Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)
But I removed Mozilla/4.0 and that fixed the IE8Beta, but IE8 final release is still redirecting. That will take some more looking into.
#24 / Sep 12, 2009 2:22pm
Thanks jeramiah for the time you take to read my post and comment on it.
For now (until we can find a better solution) i embeded the whole page. But still looking for a solution to have the task done in the proper way.
#25 / Sep 12, 2009 2:31pm
No problem, I’ll be in and out this weekend but I’ll focus on it this upcoming week. Thanks.
#26 / Sep 12, 2009 4:35pm
zedEye why are you mixing EE conditionals and PHP? I’d use one or the other, and you’ll find that your expectations will be easily matched. In your specific case, PHP is parsed before advanced EE-syntax conditionals can be evaluated, so the header() function will always execute.
#27 / Sep 12, 2009 5:15pm
I tried {redirect} but it didn’t work. That’s why the php code. Is there anything else in EE that can be used to do the job?
#28 / Sep 12, 2009 5:36pm
You could either use PHP for your conditionals, so that you’re not mixing two different types of control structures. Or, use the redirect variable. Just saying “it didn’t work” without providing full details of what you tried and how it failed won’t help you towards a solution, though. Check first that you are using a version of ExpressionEngine that supports this feature. If you are and it’s still not working, I’d recommend posting in the technical support forums for assistance.
#29 / Sep 14, 2009 12:49am
Just get rid of this line:
$var[66] = 'NEC';IE 8 will not redirect to the mobile version after that.