Skip to content

Commit

Permalink
Merge pull request MattWilcox#34 from gerv/patch-1
Browse files Browse the repository at this point in the history
Fix browser detection to be more future-proof - check for mobile browsers instead of desktop ones.
  • Loading branch information
MattWilcox committed Feb 17, 2012
2 parents be3d3bc + 176d57b commit 9c58889
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions adaptive-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@
NOTE: only required to work around a bug where some browsers can't set the cookie fast enough on the first visit to the
website. Such browsers therefor act as though no cookie was set on the very first visit. This means we can't
allow desktop browsers to have $mobile_first = TRUE (which we don't want anyway) */
function browser_detect() {
function is_mobile() {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

// Identify the OS platform. Match only desktop OSs
if (
strpos($userAgent,'macintosh') ||
strpos($userAgent,'windows nt') ||
strpos($userAgent,'x11')
) {
return TRUE;
}
return strpos($userAgent, 'mobile');
}

/* Do we need to switch mobile first off? */
if(browser_detect()){
if(!is_mobile()){
$mobile_first = FALSE;
}

Expand Down

0 comments on commit 9c58889

Please sign in to comment.