mobile detection feature
  • We've recently run into some caching issues which prohibited us from using 3rd-party PHP mobile device detection scripts. Given how frequently mobile versions of sites are requested, it would be great if there were some built-in functionality for swapping out templates/files for mobile users, either incorporating user_agent to or tags. I have more specific ideas for how it could work, but wanted to see what Vae's initial feeling was on the mobile-detection question.

  • 6 Answers sorted by
  • just being able to grab the $_SERVER['HTTP_USER_AGENT'] parameter would be a huge improvement!

  • I'd be willing to add this to our overall caching scheme. Can you provide a reliable function that detects a mobile user agent? Then I could make it available as mobile() and add that to the list of things that is differentiated in the cache.

  • Great! One caveat of note is that sometimes you want tablets to be treated as mobile and other times you don't. So maybe that could be a site-level settings checkbox?

    This one is ideal:
    http://wurfl.sourceforge.net/

    I have also used these before:
    http://code.google.com/p/php-mobile-detect/

    http://mobiforge.com/developing/story/lightweight-device-detection-php

    If none these seem workable, I can find some others.


  • Any update on this?

  • I agree with Michael, just having the User-Agent available would make it trivial to monkey patch $_REQUEST object with something like this:

    __vae.php:
    // From https://gist.github.com/1503252
    $pattern = '/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/';

    $_REQUEST['mobile'] = preg_match($pattern, $_SERVER['HTTP_USER_AGENT']);


    template.html:
    <v:if param="mobile">Hello mobile!</v:if>

  • Bumping this again

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion