Detecting document is being accessed from a mobile device

I was just wondering if there exists a simple method to detect server side that the current document is being accessed/viewed from a mobile device. I need this information to simply ensure the correct template record is retrieved from my database (where its details are stored).

And I expect the screen resolution sizes to continue to evolve, which is why I know it is not clever or future proof to use this as the determining factor when deciding whether or not to load a mobile template/stylesheet.

I’m all for fluid designs, but I would rather load a template designed primarily for mobile viewing which is a scaled down version of the website compared to when a person is viewing it from the comfort of their home/office on a large screen. It stems from a desire to streamline not only the look, but also the structure and content of the website.

Thanks for the advice guys. I’ve come across more than a few scripts that appear to accomplish what I’m looking for, and will give them each a go before deciding on one.

you can also detect the browser screen size anything smaller than 480px etc etc…

iPhone 4 is 640x960. There are a few Android based devices in the neighborhood of 400x854.

uhh there’s plenty of scripts out there …
looks for Detect mobile phone class files

you can also detect the browser screen size anything smaller than 480px etc etc…

server host will also display iphone, android, ipad, cingular, verizonmobile,tmobile, etc…

Well of course with most technologies there’s always growth and changes; hence gives us job security; however until the industry / market decides on standard we have to assuming based on Screen resolution or just design mobile sites based on the most popular phones. If we look at the market, ads, trends… iPhone & Android are the preferred choices for consumers for surfing the web, shopping

I use my android to shop for better prices while i’m at Target, Bestbuy, Walmart etc… if you go on either of those websites you’ll see they detect i’m using a mobile device and redirect me to a mobile version of their website which is really cool.

Just following up on this, I’ve done comprehensive research on all of these frameworks and the major problem is that while they can successfully pick up on certain devices, they don’t work comprehensively enough to be depended upon. On average, 15-17 new devices are released every week and over 300,000 independent devices with their own unique limitations and requirements exist. No script tests for them all and if they did it would be several megabytes to download - before the site even loaded (some even fake their header to look like a desktop browser). The problem is that using these scripts not only increase the overhead on your sites loading, it damages the user-experience if you force the consumer to use a slimmed down version of a site when they prefer the full screen interface (as many phones support full screen sites with zoom scaling). I am all for streamlined experiences and I recommend you have a separate mobile friendly design, but I (and every study I’ve seen) recommends simply letting the user pick rather than forcing a redirect which will increase the learning curve and reduce the choice users have. :slight_smile:

I agree. You don’t really care about the mobile. The issue is what functionality and screen size do you have to work with. Granted mobile devices have extreme issues on both counts, but don’t get confused that you’re trying to deal with “mobile”. You’re detecting functionality. I believe that you can’t independently get screen resolution server side. That’s not something specified in the HTTP headers. If you’re doing it yourself, you’ll need a javascript to run on page load, give you the info, and then reserve a modified page to deal with that screen resolution. Personally, I preempt a lot of that by building fluid designs and testing them down to 200 - 300 px wide range, and I try both Opera and it’s Shift+F11 “mini” mode that imitates Opera-Mini, one of the most popular mobile browsers.

You can also find frameworks that wrap up a lot of that Javascript functionality to make it look like screen resolution is detectable by PHP. If you don’t want to be tied to that framework, you can search for “Javascript screen resolution” and start narrowing your search. However, if you’re already using a framework, I’d check the documentation to see if something like that is included.

I don’t think there is.