homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

is UserAgent PHP Detection correct?

Msg#: 4259303 posted 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.



# smartphone
(ereg("iPhone", $ua))
|| (ereg("Android", $ua))
|| (ereg("Windows Phone", $ua))
|| (ereg("BlackBerry", $ua))
$flg = 's';
# mobile
(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
$flg = 'p';


Thank you for your interest :-D



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4259303 posted 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 :)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved