Linked by Eugenia Loli-Queru on Thu 24th Apr 2008 22:45 UTC
Internet & Networking We were always proud of OSNews' (and Gnomefiles.org's) mobile capabilities. We spent years collecting keywords to be able to automatically redirect or serve a mobile-formatted or WAP-formatted (wap.osnews.com) page to less capable browsers. We believe that this script can recognize 99% of the world's non-desktop browsers. We gave special care to not only phones, but PDAs, gaming devices, text browsers, even weird embedded systems browsers that most users have never heard of. Now, it's time to open source our PHP detection script so others can use it on their sites too. Download here, and read the included readme.txt file too before using. It explains what is what, and what its difference is compared to similar solutions found elsewhere. You can see the work this detection script does in our mobile statistics (OSNews serves about 1500 pageviews per day on non-desktop browsers via this script).
Thread beginning with comment 311383
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Comment by deathshadow
by Eugenia on Fri 25th Apr 2008 02:35 UTC in reply to "Comment by deathshadow"
Eugenia
Member since:
2005-06-28

No, there was a reason why I wanted each keyword on its own line: so I can identify keywords and add a set of special variables if a specific keyword is set, and then later, modify my HTML code based on these variables. Because you see, there were some phones or some versions of browsers that required special cHTML writing because of bugs, so I had to exclude them like that. You don't see that in the version of the code I provided, but the original we used on osnews has those exceptions in. It was much more readable for me to do it like this instead of putting everything into arrays.

Edited 2008-04-25 02:36 UTC

Reply Parent Bookmark Score: 1

RE[2]: Comment by deathshadow
by prickett on Fri 25th Apr 2008 03:03 in reply to "RE: Comment by deathshadow"
prickett Member since:
2007-04-03

Please show us the code your talking about, because whilst the gesture of offering this work is a great thing, the programming itself is extremely amateurish and we could help you improve and at the end of the day everybody wins.

Edited 2008-04-25 03:04 UTC

Reply Parent Bookmark Score: 1

RE[3]: Comment by deathshadow
by Eugenia on Fri 25th Apr 2008 03:08 in reply to "RE[2]: Comment by deathshadow"
Eugenia Member since:
2005-06-28

I explained what the additional code does. For example, if you hit Nokia Services and opera mini 2.0, you set an additional variable. Then, in your code, you say something like this:
if nokia services version 3.01 and opera mini 2.0, width 95% instead of 100%.
Stuff like that. You simply create special variables to identify some bugs of some versions/browsers and then you code the cHTML in a different way. I have some such code for nokia communicator, links etc.

If you really want to know about all these bugs these browsers have, you will have to experiment yourselves, get devices, emulators etc. I had to do all that.

Edited 2008-04-25 03:09 UTC

Reply Parent Bookmark Score: 1

RE[2]: Comment by deathshadow
by ohbrilliance on Fri 25th Apr 2008 03:36 in reply to "RE: Comment by deathshadow"
ohbrilliance Member since:
2005-07-07

I understand that there's a historical reason to separate the ifs rather than running the more efficient 'if/else', but since the code no longer needs to function in that manner, why not convert all but the first clause into an 'else' statement? Really seems baffling that you've left it as-is. Or have I misunderstood something?

Reply Parent Bookmark Score: 2

RE[3]: Comment by deathshadow
by Eugenia on Fri 25th Apr 2008 03:43 in reply to "RE[2]: Comment by deathshadow"
Eugenia Member since:
2005-06-28

Feel free to put the keywords on arrays. I just put together on the zip file a cleaned up version of what we use, I didn't refactor it. Besides, you will need to change the istr() too, so some work will have to be done if some people want to use it anyway.

I don't do osnews much anymore, neither I code mobile sites anymore, so I didn't put lots of love on this version.

Reply Parent Bookmark Score: 1

deathshadow Member since:
2005-07-12

why not convert all but the first clause into an 'else' statement? Really seems baffling that you've left it as-is. Or have I misunderstood something?

That was my first reaction looking at the code - Even WITH overloading, you overload the ones you NEED TO and not overload the others.

I can 'kind of' see why it's not done, but in that case you just reverse the orders. Right now EVERY run of this code would execute all 267 if statements - when most of the time there should be a way to run a LOT less of those.

For example, how many of those also return 'internet explorer' in their user agent strings? Separate those off so that you aren't testing those unless you need to. One extra IF saving you several dozen unneccessary ones... How many of those return width and height with their string? If that's overloading, test those first and short-circuit testing the rest...

And if you need to add special conditions, wouldn't a case statement AFTER the if's be just as good?

I also notice in the comments that it used to use preg_match - Wouldn't that cut down on false positives and remove the need for a lot of the extra checks?

Silly question, do you have a list formed of the user agent strings on which you made this code? I'm thinking there has to be a faster/easier/cleaner way of handling this, but I can't entirely make assumptions because I'm not certain what conditions would overload others and what takes precedence.

Reply Parent Bookmark Score: 3