| is UserAgent PHP Detection correct?
|
m14ktm

msg:4259305 | 6:03 am on Jan 28, 2011 (gmt 0) | Hello, this is my very first post :-D I'm a web developer from Japan. Recently I start to creating a website for smartphone. I think this User Agent detection (PHP) is correct. Are they correct? Please help me out. _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ $ua = $_SERVER['HTTP_USER_AGENT']; # smartphone if ( (ereg("iPhone", $ua)) || (ereg("Android", $ua)) || (ereg("Windows Phone", $ua)) || (ereg("BlackBerry", $ua)) ) { $flg = 's'; } # mobile elseif( (ereg("DoCoMo", $ua)) || (ereg("SoftBank", $ua)) || (ereg("Vodafone", $ua)) || (ereg("J-PHONE", $ua)) || (ereg("UP.Browser", $ua)) || (ereg("KDDI", $ua)) || (ereg("WILLCOM", $ua)) || (ereg("DDIPOCKET", $ua)) || (ereg("PDXGW", $ua)) || (ereg("Googlebot-Mobile", $ua)) || (ereg("Y!J", $ua)) || (ereg("LD_mobile_bot", $ua)) || (ereg("moba-crawler", $ua)) || (ereg("RFCrawler-Mobile", $ua)) || (ereg("froute.jp", $ua)) || (ereg("ichiro", $ua)) ) { $flg = 'm'; } # PC else { $flg = 'p'; } _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Thank you for your interest :-D
|
Matthew1980

msg:4259322 | 8:18 am on Jan 28, 2011 (gmt 0) | Hi there m14ktm, Welcome to the forum! Only one thing to point out with your code: ereg() [uk3.php.net] is now deprecated, so make sure that where you run this code is running the older version (which is fewer now), OR convert to preg_match() [uk3.php.net] so that you can have backwards and forwards compatibility where ever you run your script. You code will then only need a minor tweek in the pattern area, so something like this:- ereg("iPhone", $ua); would (I think) turn into this:- preg_match("/^iPhone$/i", $ua);<- i just means case insensitive but can be omitted.. Though I am sure as I will be corrected there :) Cheers, MRb
|
|
|