Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats better to redirect, screen resolution or user agent? [closed]

I've created a mobile web page for a site but I'm wondering what the best method for redirection is. Do I redirect them based on the screen resolution or the user agent?

I would assume screen resolution would look something like this:

if (screen.width <= 1024) window.location.replace("http://www.site/mobile/")
else window.location.replace("http://www.site/");

Using PHP the script would look something like this:

$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/android/i',substr($useragent,0,4)))
header('Location: http://www,site/mobile/');

Is one method preferred over the other? If so what are the advantages?

like image 344
Paul Avatar asked Dec 03 '12 20:12

Paul


1 Answers

User agent.

In this day and age of retina displays and the fact that an Android device can be any screen resolution you can think of, there's increasingly less correlation between screen resolution and platform. In fact, there are many mobile devices (nexus 7, nexus 10, ipad 3+) with the same or greater screen resolution than desktop computers. Resolution is simply not descriptive enough.

User agent, on the other hand, is designed to tell you what's making the request. You'll know without a doubt that it's an Android or iOS device. Also, on Android, I believe tablets are not supposed to include the string "mobile" within their Android-y user-agent, for even better targeting. Similarly, the iPad and iPhone each have their own set of user agent strings that you can account for.

like image 117
Sam Dozor Avatar answered Nov 09 '22 06:11

Sam Dozor