What code can I write that senses whether my user is on a mobile phone as opposed to a desktop?

Posted on 2012-08-29
Last Modified: 2012-08-30
I am curious to know whether there's some script I can write that determines whether or not my user is attempting to access my site using a computer browser or a phone. In the event that they're using a phone, I'm wanting to redirect them to a more mobile friendly site.

Can it be done and if so, how?
Question by:brucegust
    LVL 8

    Assisted Solution

    by:Ahmed Merghani
    You can use this class:
    I think this is what you need.
    LVL 36

    Assisted Solution

    by:Loganathan Natarajan
    You could also try this script,
    LVL 34

    Accepted Solution

    Depending on user agent strings can be hit and miss. A better way may be to look at CSS3 capabilities. Most mobile devices fully implement CSS3 media queries

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now