Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:33:42+00:00 2026-06-10T01:33:42+00:00

I have a website with a full browser and jQuery Mobile interface and users

  • 0

I have a website with a full browser and jQuery Mobile interface and users can switch between the two. Their preference is stored in a cookie. By default the site serves the full version to visitors whitout a preference cookie, but to make it better for modern smartphone users I want their default to be JQM. So, I have this code in the constructor of my base controller class:

class BaseController
{

    protected $mobile;  // must be 0 or 1, cookies can't handle boolean 'false'

    public function __construct()
    {
        if (isset($_COOKIE['mobile']))
        {
            $this->mobile = $_COOKIE['mobile'];
        }
        else
        {
            $this->mobile = $this->isSmartphoneWithCookies();
            setcookie("mobile", $this->mobile, time() + 7776000, '/', ''); // 90 days
        }
    }

    private function isSmartphoneWithCookies()
    {
        $SMARTPHONE_WITH_COOKIES = "android.+mobile|blackberry|ip(hone|od)|opera m(ob|in)i";

        return preg_match("/$SMARTPHONE_WITH_COOKIES/i", $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
    }

    // the rest of my controller class....
}

Here I prefer speed to accuracy, so I am not looking for a slower, up-to-date lookup service as suggested here: Simple Smart Phone detection

Just a quick indication that the visitor has one of the current top smartphone/tablet browsers that support cookies and JQM.

Can someone suggest an improvement for my $SMARTPHONE_WITH_COOKIES? Or point me to a collection of UA signatures that fit my use case? Specifically, is it safe to have blackberry in the list? Am I overlooking a popular capable browser?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:33:44+00:00Added an answer on June 10, 2026 at 1:33 am

    By design, the primary UI selector for my app is the user. I do not want to delegate that to a detection script. The bit of detection in question is just to give a clever default. It is a risky feature, because a false positive (for example a smartphone without cookie support) can make my site totally inaccessible to some users. So if it fails, it needs to fail towards the standard interface.

    For what it’s worth, I considered the following:

    • Opera Mini doesn’t have good enough javascript support for my JQM
      app.
    • Opera Mobile running on Android is a major category that I would
      have loved to catch, but I am not confident enough that I can
      correctly pick all of that out of the UA string.
    • I considered “windows phone os 7”, but decided it will date too quickly
    • The subset of Blackberry browsers that qualify is also too tricky to detect
      simply, so rather than risk a false positive, I decided to drop the
      whole tier.

    So, what I am left with is:

    $SMARTPHONE_WITH_COOKIES = "android.+mobile|iphone|ipod";
    

    The cost of keeping it this light and simple is that I will have to reconsider this question again every two years or so. I will also have many mobile visitors that will need to do an extra click to get the mobile version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have website where users can login with their Facebook account. I am using
In my website I have implemented search feature using full-text search. It works fine
So basically I have website that has names of cities that can be checked
I'm trying to play on iPhone's Safari so i can have website menu bar
I'm using jQuery. I have website feature that does an ajax search and returns
Note: I'm using jQuery and jQuery Mobile. I have a mobile page which seems
Let's say we have a mobile-friendly website www.mywebsite.com that I want to quickly turn
I have a very basic two-page website: the home page, and an about page.
I have a website will have a background that is the full size of
I have a website that would ideally be accessed by users who have downloaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.